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