10#include "clang/AST/ASTContext.h"
11#include "clang/ASTMatchers/ASTMatchFinder.h"
20 decl(hasParent(translationUnitDecl()), unless(linkageSpecDecl()))
21 .bind(
"child_of_translation_unit"),
26 const MatchFinder::MatchResult &Result) {
27 const auto *MatchedDecl =
28 Result.Nodes.getNodeAs<
Decl>(
"child_of_translation_unit");
29 if (!Result.SourceManager->isInMainFile(MatchedDecl->getLocation()))
32 if (
const auto *NS = dyn_cast<NamespaceDecl>(MatchedDecl)) {
34 diag(NS->getLocation(),
"'%0' needs to be the outermost namespace")
39 diag(MatchedDecl->getLocation(),
40 "declaration must be declared within the '%0' namespace")
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 StringRef RequiredNamespace