10 #include "clang/AST/ASTContext.h"
11 #include "clang/ASTMatchers/ASTMatchFinder.h"
12 #include "clang/ASTMatchers/ASTMatchers.h"
13 #include "clang/Lex/Lexer.h"
20 namespace readability {
22 GlobalNamesInHeadersCheck::GlobalNamesInHeadersCheck(StringRef
Name,
25 RawStringHeaderFileExtensions(Options.getLocalOrGlobal(
30 llvm::errs() <<
"Invalid header file extension: "
31 << RawStringHeaderFileExtensions <<
"\n";
37 Options.
store(Opts,
"HeaderFileExtensions", RawStringHeaderFileExtensions);
41 ast_matchers::MatchFinder *Finder) {
42 Finder->addMatcher(decl(anyOf(usingDecl(), usingDirectiveDecl()),
43 hasDeclContext(translationUnitDecl()))
49 const auto *D = Result.Nodes.getNodeAs<
Decl>(
"using_decl");
51 if (D->getBeginLoc().isMacroID())
55 if (Result.SourceManager->isInMainFile(
56 Result.SourceManager->getExpansionLoc(D->getBeginLoc()))) {
59 D->getBeginLoc(), *Result.SourceManager, HeaderFileExtensions))
63 if (
const auto *UsingDirective = dyn_cast<UsingDirectiveDecl>(D)) {
64 if (UsingDirective->getNominatedNamespace()->isAnonymousNamespace()) {
73 diag(D->getBeginLoc(),
74 "using declarations in the global namespace in headers are prohibited");