10#include "clang/AST/ASTContext.h"
11#include "clang/ASTMatchers/ASTMatchFinder.h"
12#include "clang/ASTMatchers/ASTMatchers.h"
13#include "clang/Lex/Lexer.h"
22 HeaderFileExtensions(Context->getHeaderFileExtensions()) {}
25 ast_matchers::MatchFinder *Finder) {
26 Finder->addMatcher(decl(anyOf(usingDecl(), usingDirectiveDecl()),
27 hasDeclContext(translationUnitDecl()))
33 const auto *D = Result.Nodes.getNodeAs<
Decl>(
"using_decl");
35 if (D->getBeginLoc().isMacroID())
39 if (Result.SourceManager->isInMainFile(
40 Result.SourceManager->getExpansionLoc(D->getBeginLoc()))) {
43 D->getBeginLoc(), *Result.SourceManager, HeaderFileExtensions))
47 if (
const auto *UsingDirective = dyn_cast<UsingDirectiveDecl>(D)) {
48 if (UsingDirective->getNominatedNamespace()->isAnonymousNamespace()) {
57 diag(D->getBeginLoc(),
58 "using declarations in the global namespace in headers are prohibited");
const FunctionDecl * Decl
llvm::SmallString< 256U > Name
Base class for all clang-tidy checks.
DiagnosticBuilder diag(SourceLocation Loc, StringRef Description, DiagnosticIDs::Level Level=DiagnosticIDs::Warning)
Add a diagnostic with the check's name.
Every ClangTidyCheck reports errors through a DiagnosticsEngine provided by this context.
bool isSpellingLocInHeaderFile(SourceLocation Loc, SourceManager &SM, const FileExtensionsSet &HeaderFileExtensions)
Checks whether spelling location of Loc is in header file.