29 if (matchesFirstInRange(InnerMatcher, PackArgs.begin(), PackArgs.end(),
33 return matchesFirstInRange(InnerMatcher, Args.begin(), Args.end(), Finder,
55 const auto HasStdParent =
56 hasDeclContext(namespaceDecl(hasAnyName(
"std",
"posix"),
57 unless(hasParent(namespaceDecl())))
61 const auto UserDefinedDecl =
62 namedDecl(anyOf(classTemplateDecl(), tagDecl()),
63 hasDeclContext(isInStdOrPosixNamespace()));
64 const auto UserDefinedType = qualType(hasUnqualifiedDesugaredType(anyOf(
65 tagType(unless(hasDeclaration(UserDefinedDecl))),
66 templateSpecializationType(unless(hasDeclaration(UserDefinedDecl))))));
67 const auto HasNoProgramDefinedTemplateArgument = unless(
68 hasAnyTemplateArgumentIncludingPack(refersToType(UserDefinedType)));
69 const auto InsideStdClassOrClassTemplateSpecialization = hasDeclContext(
70 anyOf(cxxRecordDecl(HasStdParent),
71 classTemplateSpecializationDecl(
72 HasStdParent, HasNoProgramDefinedTemplateArgument)));
93 auto BadNonTemplateSpecializationDecl =
94 decl(unless(anyOf(functionDecl(isExplicitTemplateSpecialization()),
95 varDecl(isExplicitTemplateSpecialization()),
96 cxxRecordDecl(isExplicitTemplateSpecialization()))),
98 auto BadClassTemplateSpec = classTemplateSpecializationDecl(
99 HasNoProgramDefinedTemplateArgument, HasStdParent);
100 auto BadInnerClassTemplateSpec = classTemplateSpecializationDecl(
101 InsideStdClassOrClassTemplateSpecialization);
102 auto BadFunctionTemplateSpec =
103 functionDecl(unless(cxxMethodDecl()), isExplicitTemplateSpecialization(),
104 HasNoProgramDefinedTemplateArgument, HasStdParent);
105 auto BadMemberFunctionSpec =
106 cxxMethodDecl(isExplicitTemplateSpecialization(),
107 InsideStdClassOrClassTemplateSpecialization);
109 Finder->addMatcher(decl(anyOf(BadNonTemplateSpecializationDecl,
110 BadClassTemplateSpec, BadInnerClassTemplateSpec,
111 BadFunctionTemplateSpec, BadMemberFunctionSpec))
128 const MatchFinder::MatchResult &Result) {
129 const auto *D = Result.Nodes.getNodeAs<Decl>(
"decl");
130 const auto *NS = Result.Nodes.getNodeAs<NamespaceDecl>(
"nmspc");
138 diag(D->getLocation(),
139 "modification of %0 namespace can result in undefined behavior")
144 assert(NS->getCanonicalDecl() == LexNS->getCanonicalDecl() &&
145 "Mismatch in found namespace");
146 diag(LexNS->getLocation(),
"%0 namespace opened here", DiagnosticIDs::Note)