58 Finder->addMatcher(usingDecl(isExpansionInMainFile()).bind(
"using"),
this);
59 auto DeclMatcher = hasDeclaration(namedDecl().bind(
"used"));
60 Finder->addMatcher(loc(templateSpecializationType(DeclMatcher)),
this);
61 Finder->addMatcher(loc(deducedTemplateSpecializationType(
62 refsToTemplatedDecl(namedDecl().bind(
"used")))),
64 Finder->addMatcher(callExpr(callee(unresolvedLookupExpr().bind(
"used"))),
67 callExpr(hasDeclaration(functionDecl(
68 forEachTemplateArgument(templateArgument().bind(
"used"))))),
70 Finder->addMatcher(loc(templateSpecializationType(forEachTemplateArgument(
71 templateArgument().bind(
"used")))),
73 Finder->addMatcher(userDefinedLiteral().bind(
"used"),
this);
74 Finder->addMatcher(loc(asTagDecl(tagDecl().bind(
"used"))),
this);
78 auto ThroughShadowMatcher = throughUsingDecl(namedDecl().bind(
"usedShadow"));
79 Finder->addMatcher(declRefExpr(ThroughShadowMatcher),
this);
80 Finder->addMatcher(loc(usingType(ThroughShadowMatcher)),
this);
84 if (Result.Context->getDiagnostics().hasUncompilableErrorOccurred())
87 if (
const auto *Using = Result.Nodes.getNodeAs<UsingDecl>(
"using")) {
89 if (Using->getLocation().isMacroID())
93 if (isa<CXXRecordDecl>(Using->getDeclContext()))
99 if (isa<FunctionDecl>(Using->getDeclContext()))
102 UsingDeclContext Context(Using);
103 Context.UsingDeclRange = CharSourceRange::getCharRange(
104 Using->getBeginLoc(),
105 Lexer::findLocationAfterToken(
106 Using->getEndLoc(), tok::semi, *Result.SourceManager, getLangOpts(),
108 for (
const auto *UsingShadow : Using->shadows()) {
109 const auto *TargetDecl = UsingShadow->getTargetDecl()->getCanonicalDecl();
111 Context.UsingTargetDecls.insert(TargetDecl);
112 UsingTargetDeclsCache.insert(TargetDecl);
115 if (!Context.UsingTargetDecls.empty())
116 Contexts.push_back(Context);
121 auto RemoveNamedDecl = [&](
const NamedDecl *Used) {
122 removeFromFoundDecls(Used);
124 if (
const auto *FD = dyn_cast<FunctionDecl>(Used)) {
125 removeFromFoundDecls(FD->getPrimaryTemplate());
128 if (
const auto *Specialization =
129 dyn_cast<ClassTemplateSpecializationDecl>(Used)) {
130 removeFromFoundDecls(Specialization->getSpecializedTemplate());
133 if (
const auto *ECD = dyn_cast<EnumConstantDecl>(Used)) {
134 if (
const auto *ET = ECD->getType()->getAsCanonical<EnumType>())
135 removeFromFoundDecls(ET->getOriginalDecl());
140 if (
const auto *Used = Result.Nodes.getNodeAs<NamedDecl>(
"used")) {
141 RemoveNamedDecl(Used);
145 if (
const auto *UsedShadow =
146 Result.Nodes.getNodeAs<UsingShadowDecl>(
"usedShadow")) {
147 removeFromFoundDecls(UsedShadow->getTargetDecl());
151 if (
const auto *Used = Result.Nodes.getNodeAs<TemplateArgument>(
"used")) {
152 if (Used->getKind() == TemplateArgument::Template) {
153 if (
const auto *TD = Used->getAsTemplate().getAsTemplateDecl())
154 removeFromFoundDecls(TD);
158 if (Used->getKind() == TemplateArgument::Type) {
159 if (
auto *RD = Used->getAsType()->getAsCXXRecordDecl())
160 removeFromFoundDecls(RD);
164 if (Used->getKind() == TemplateArgument::Declaration) {
165 RemoveNamedDecl(Used->getAsDecl());
170 if (
const auto *DRE = Result.Nodes.getNodeAs<DeclRefExpr>(
"used")) {
171 RemoveNamedDecl(DRE->getDecl());
175 if (
const auto *ULE = Result.Nodes.getNodeAs<UnresolvedLookupExpr>(
"used")) {
176 for (
const NamedDecl *ND : ULE->decls()) {
177 if (
const auto *USD = dyn_cast<UsingShadowDecl>(ND))
178 removeFromFoundDecls(USD->getTargetDecl()->getCanonicalDecl());
183 if (
const auto *UDL = Result.Nodes.getNodeAs<UserDefinedLiteral>(
"used")) {
184 const Decl *CalleeDecl = UDL->getCalleeDecl();
185 if (
const auto *FD = dyn_cast<FunctionDecl>(CalleeDecl)) {
186 if (
const FunctionTemplateDecl *FPT = FD->getPrimaryTemplate()) {
187 removeFromFoundDecls(FPT);
191 removeFromFoundDecls(CalleeDecl);
Every ClangTidyCheck reports errors through a DiagnosticsEngine provided by this context.