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) {
23 Finder->addMatcher(usingDirectiveDecl().bind(
"usingNamespace"),
this);
26 void UsingNamespaceDirectiveCheck::check(
27 const MatchFinder::MatchResult &Result) {
28 const auto *U = Result.Nodes.getNodeAs<UsingDirectiveDecl>(
"usingNamespace");
29 SourceLocation
Loc = U->getBeginLoc();
30 if (U->isImplicit() || !
Loc.isValid())
35 if (isStdLiteralsNamespace(U->getNominatedNamespace()))
38 diag(
Loc,
"do not use namespace using-directives; "
39 "use using-declarations instead");
44 bool UsingNamespaceDirectiveCheck::isStdLiteralsNamespace(
45 const NamespaceDecl *NS) {
46 if (!NS->getName().endswith(
"literals"))
49 const auto *
Parent = dyn_cast_or_null<NamespaceDecl>(NS->getParent());
53 if (
Parent->isStdNamespace())
56 return Parent->getName() ==
"literals" &&
Parent->getParent() &&
57 Parent->getParent()->isStdNamespace();