11 #include "clang/AST/ASTContext.h" 12 #include "clang/ASTMatchers/ASTMatchFinder.h" 13 #include "clang/ASTMatchers/ASTMatchers.h" 22 void UsingNamespaceDirectiveCheck::registerMatchers(
23 ast_matchers::MatchFinder *Finder) {
26 if (getLangOpts().CPlusPlus)
27 Finder->addMatcher(usingDirectiveDecl().bind(
"usingNamespace"),
this);
30 void UsingNamespaceDirectiveCheck::check(
31 const MatchFinder::MatchResult &
Result) {
32 const auto *U = Result.Nodes.getNodeAs<UsingDirectiveDecl>(
"usingNamespace");
33 SourceLocation
Loc = U->getBeginLoc();
34 if (U->isImplicit() || !Loc.isValid())
39 if (isStdLiteralsNamespace(U->getNominatedNamespace()))
42 diag(Loc,
"do not use namespace using-directives; " 43 "use using-declarations instead");
48 bool UsingNamespaceDirectiveCheck::isStdLiteralsNamespace(
49 const NamespaceDecl *NS) {
50 if (!NS->getName().endswith(
"literals"))
53 const auto *Parent = dyn_cast_or_null<NamespaceDecl>(NS->getParent());
57 if (Parent->isStdNamespace())
60 return Parent->getName() ==
"literals" && Parent->getParent() &&
61 Parent->getParent()->isStdNamespace();
SourceLocation Loc
'#' location in the include directive
llvm::Optional< llvm::Expected< tooling::AtomicChanges > > Result
===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===//