11 #include "clang/AST/ASTContext.h" 12 #include "clang/ASTMatchers/ASTMatchFinder.h" 20 void DontModifyStdNamespaceCheck::registerMatchers(MatchFinder *Finder) {
21 if (!getLangOpts().CPlusPlus)
25 namespaceDecl(unless(isExpansionInSystemHeader()),
26 anyOf(hasName(
"std"), hasName(
"posix")),
27 has(decl(unless(anyOf(
28 functionDecl(isExplicitTemplateSpecialization()),
29 cxxRecordDecl(isExplicitTemplateSpecialization()))))))
34 void DontModifyStdNamespaceCheck::check(
35 const MatchFinder::MatchResult &Result) {
36 const auto *N = Result.Nodes.getNodeAs<NamespaceDecl>(
"nmspc");
39 if (N->getParent() != Result.Context->getTranslationUnitDecl())
42 diag(N->getLocation(),
43 "modification of %0 namespace can result in undefined behavior")