[InstCombine] Drop range attributes in `foldBitCeil` (#116641)
[llvm-project.git] / clang-tools-extra / clang-tidy / google / UnnamedNamespaceInHeaderCheck.cpp
blob34ddd7623bf5e9e85509b6f5451befe274decb45
1 //===--- UnnamedNamespaceInHeaderCheck.cpp - clang-tidy ---------*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
9 #include "UnnamedNamespaceInHeaderCheck.h"
10 #include "clang/AST/ASTContext.h"
11 #include "clang/ASTMatchers/ASTMatchFinder.h"
12 #include "clang/ASTMatchers/ASTMatchers.h"
14 using namespace clang::ast_matchers;
16 namespace clang::tidy::google::build {
18 UnnamedNamespaceInHeaderCheck::UnnamedNamespaceInHeaderCheck(
19 StringRef Name, ClangTidyContext *Context)
20 : ClangTidyCheck(Name, Context),
21 HeaderFileExtensions(Context->getHeaderFileExtensions()) {}
23 void UnnamedNamespaceInHeaderCheck::registerMatchers(
24 ast_matchers::MatchFinder *Finder) {
25 Finder->addMatcher(namespaceDecl(isAnonymous()).bind("anonymousNamespace"),
26 this);
29 void UnnamedNamespaceInHeaderCheck::check(
30 const MatchFinder::MatchResult &Result) {
31 const auto *N = Result.Nodes.getNodeAs<NamespaceDecl>("anonymousNamespace");
32 SourceLocation Loc = N->getBeginLoc();
33 if (!Loc.isValid())
34 return;
36 if (utils::isPresumedLocInHeaderFile(Loc, *Result.SourceManager,
37 HeaderFileExtensions))
38 diag(Loc, "do not use unnamed namespaces in header files");
41 } // namespace clang::tidy::google::build