10#include "clang/AST/ASTContext.h"
11#include "clang/ASTMatchers/ASTMatchFinder.h"
12#include "clang/ASTMatchers/ASTMatchersInternal.h"
19AST_POLYMORPHIC_MATCHER_P(
20 hasAnyTemplateArgumentIncludingPack,
21 AST_POLYMORPHIC_SUPPORTED_TYPES(ClassTemplateSpecializationDecl,
22 TemplateSpecializationType, FunctionDecl),
23 clang::ast_matchers::internal::Matcher<TemplateArgument>, InnerMatcher) {
24 ArrayRef<TemplateArgument>
Args =
25 clang::ast_matchers::internal::getTemplateSpecializationArgs(Node);
26 for (
const auto &Arg :
Args) {
27 if (Arg.getKind() != TemplateArgument::Pack)
29 ArrayRef<TemplateArgument> PackArgs = Arg.getPackAsArray();
30 if (matchesFirstInRange(InnerMatcher, PackArgs.begin(), PackArgs.end(),
31 Finder,
Builder) != PackArgs.end())
34 return matchesFirstInRange(InnerMatcher,
Args.begin(),
Args.end(), Finder,
44 hasDeclContext(namespaceDecl(hasAnyName(
"std",
"posix"),
45 unless(hasParent(namespaceDecl())))
47 auto UserDefinedType = qualType(
48 hasUnqualifiedDesugaredType(tagType(unless(hasDeclaration(tagDecl(
49 hasAncestor(namespaceDecl(hasAnyName(
"std",
"posix"),
50 unless(hasParent(namespaceDecl()))))))))));
51 auto HasNoProgramDefinedTemplateArgument = unless(
52 hasAnyTemplateArgumentIncludingPack(refersToType(UserDefinedType)));
53 auto InsideStdClassOrClassTemplateSpecialization = hasDeclContext(
54 anyOf(cxxRecordDecl(HasStdParent),
55 classTemplateSpecializationDecl(
56 HasStdParent, HasNoProgramDefinedTemplateArgument)));
77 auto BadNonTemplateSpecializationDecl =
78 decl(unless(anyOf(functionDecl(isExplicitTemplateSpecialization()),
79 varDecl(isExplicitTemplateSpecialization()),
80 cxxRecordDecl(isExplicitTemplateSpecialization()))),
82 auto BadClassTemplateSpec = classTemplateSpecializationDecl(
83 HasNoProgramDefinedTemplateArgument, HasStdParent);
84 auto BadInnerClassTemplateSpec = classTemplateSpecializationDecl(
85 InsideStdClassOrClassTemplateSpecialization);
86 auto BadFunctionTemplateSpec =
87 functionDecl(unless(cxxMethodDecl()), isExplicitTemplateSpecialization(),
88 HasNoProgramDefinedTemplateArgument, HasStdParent);
89 auto BadMemberFunctionSpec =
90 cxxMethodDecl(isExplicitTemplateSpecialization(),
91 InsideStdClassOrClassTemplateSpecialization);
93 Finder->addMatcher(decl(anyOf(BadNonTemplateSpecializationDecl,
94 BadClassTemplateSpec, BadInnerClassTemplateSpec,
95 BadFunctionTemplateSpec, BadMemberFunctionSpec),
96 unless(isExpansionInSystemHeader()))
103 const NamespaceDecl *LastNS =
nullptr;
105 if (
const auto *NS = dyn_cast<NamespaceDecl>(D))
107 D = dyn_cast_or_null<Decl>(D->getLexicalDeclContext());
113 const MatchFinder::MatchResult &Result) {
114 const auto *D = Result.Nodes.getNodeAs<
Decl>(
"decl");
115 const auto *NS = Result.Nodes.getNodeAs<NamespaceDecl>(
"nmspc");
119 diag(D->getLocation(),
120 "modification of %0 namespace can result in undefined behavior")
125 assert(NS->getCanonicalDecl() == LexNS->getCanonicalDecl() &&
126 "Mismatch in found namespace");
127 diag(LexNS->getLocation(),
"%0 namespace opened here", DiagnosticIDs::Note)
const FunctionDecl * Decl
CodeCompletionBuilder Builder
static const NamespaceDecl * getTopLevelLexicalNamespaceDecl(const Decl *D)
void check(const ast_matchers::MatchFinder::MatchResult &Result) override
ClangTidyChecks that register ASTMatchers should do the actual work in here.
void registerMatchers(ast_matchers::MatchFinder *Finder) override
Override this to register AST matchers with Finder.
===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===//