11#include "clang/AST/ASTContext.h"
12#include "clang/ASTMatchers/ASTMatchFinder.h"
21 forEach(decl(isExpansionInMainFile(), unless(linkageSpecDecl()),
23 unless(usingDirectiveDecl(isImplicit())))
24 .bind(
"child_of_translation_unit"))),
29 const MatchFinder::MatchResult &Result) {
30 const auto *MatchedDecl =
31 Result.Nodes.getNodeAs<
Decl>(
"child_of_translation_unit");
32 const auto *NS = dyn_cast<NamespaceDecl>(MatchedDecl);
35 if (NS ==
nullptr || NS->isAnonymousNamespace()) {
36 diag(MatchedDecl->getLocation(),
37 "declaration must be enclosed within the '%0' namespace")
43 if (Result.SourceManager->isMacroBodyExpansion(NS->getLocation()) ==
false) {
44 diag(NS->getLocation(),
"the outermost namespace should be the '%0' macro")
52 if (NS->getVisibility() != Visibility::HiddenVisibility) {
53 diag(NS->getLocation(),
"the '%0' macro should start with '%1'")
60 diag(NS->getLocation(),
"the '%0' macro expansion should start with '%1'")
const FunctionDecl * Decl
DiagnosticBuilder diag(SourceLocation Loc, StringRef Description, DiagnosticIDs::Level Level=DiagnosticIDs::Warning)
Add a diagnostic with the check's name.
void check(const ast_matchers::MatchFinder::MatchResult &Result) override
ClangTidyChecks that register ASTMatchers should do the actual work in here.
void registerMatchers(ast_matchers::MatchFinder *Finder) override
Override this to register AST matchers with Finder.
static const llvm::StringRef RequiredNamespaceDeclStart
static const llvm::StringRef RequiredNamespaceDeclMacroName
static const llvm::StringRef RequiredNamespaceRefStart