10#include "clang/ASTMatchers/ASTMatchFinder.h"
11#include "clang/ASTMatchers/ASTMatchers.h"
18 ast_matchers::MatchFinder *Finder) {
19 Finder->addMatcher(usingDirectiveDecl().bind(
"usingNamespace"),
this);
23 const MatchFinder::MatchResult &Result) {
24 const auto *U = Result.Nodes.getNodeAs<UsingDirectiveDecl>(
"usingNamespace");
25 SourceLocation Loc = U->getBeginLoc();
26 if (U->isImplicit() || !Loc.isValid())
31 if (isStdLiteralsNamespace(U->getNominatedNamespace()))
34 diag(Loc,
"do not use namespace using-directives; "
35 "use using-declarations instead");
40bool UsingNamespaceDirectiveCheck::isStdLiteralsNamespace(
41 const NamespaceDecl *NS) {
42 if (!NS->getName().ends_with(
"literals"))
45 const auto *Parent = dyn_cast_or_null<NamespaceDecl>(NS->getParent());
49 if (Parent->isStdNamespace())
52 return Parent->getName() ==
"literals" && Parent->getParent() &&
53 Parent->getParent()->isStdNamespace();
void registerMatchers(ast_matchers::MatchFinder *Finder) override
void check(const ast_matchers::MatchFinder::MatchResult &Result) override