10#include "clang/AST/ASTContext.h"
11#include "clang/ASTMatchers/ASTMatchFinder.h"
12#include "clang/ASTMatchers/ASTMatchers.h"
19 ast_matchers::MatchFinder *Finder) {
20 Finder->addMatcher(usingDirectiveDecl().bind(
"usingNamespace"),
this);
24 const MatchFinder::MatchResult &Result) {
25 const auto *U = Result.Nodes.getNodeAs<UsingDirectiveDecl>(
"usingNamespace");
26 SourceLocation
Loc = U->getBeginLoc();
27 if (U->isImplicit() || !
Loc.isValid())
32 if (isStdLiteralsNamespace(U->getNominatedNamespace()))
35 diag(
Loc,
"do not use namespace using-directives; "
36 "use using-declarations instead");
41bool UsingNamespaceDirectiveCheck::isStdLiteralsNamespace(
42 const NamespaceDecl *NS) {
43 if (!NS->getName().ends_with(
"literals"))
46 const auto *
Parent = dyn_cast_or_null<NamespaceDecl>(NS->getParent());
50 if (
Parent->isStdNamespace())
53 return Parent->getName() ==
"literals" &&
Parent->getParent() &&
54 Parent->getParent()->isStdNamespace();
DiagnosticBuilder diag(SourceLocation Loc, StringRef Description, DiagnosticIDs::Level Level=DiagnosticIDs::Warning)
Add a diagnostic with the check's name.
void registerMatchers(ast_matchers::MatchFinder *Finder) override
Override this to register AST matchers with Finder.
void check(const ast_matchers::MatchFinder::MatchResult &Result) override
ClangTidyChecks that register ASTMatchers should do the actual work in here.