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()))
103 if (Using->hasOwningModule() &&
104 Using->getModuleOwnershipKind() <=
105 Decl::ModuleOwnershipKind::VisibleWhenImported)
108 UsingDeclContext Context(Using);
109 Context.UsingDeclRange = CharSourceRange::getCharRange(
110 Using->getBeginLoc(),
111 Lexer::findLocationAfterToken(
112 Using->getEndLoc(), tok::semi, *Result.SourceManager, getLangOpts(),
114 for (
const auto *UsingShadow : Using->shadows()) {
115 const auto *TargetDecl = UsingShadow->getTargetDecl()->getCanonicalDecl();
117 Context.UsingTargetDecls.insert(TargetDecl);
118 UsingTargetDeclsCache.insert(TargetDecl);
121 if (!Context.UsingTargetDecls.empty())
122 Contexts.push_back(Context);
127 auto RemoveNamedDecl = [&](
const NamedDecl *Used) {
128 removeFromFoundDecls(Used);
130 if (
const auto *FD = dyn_cast<FunctionDecl>(Used)) {
131 removeFromFoundDecls(FD->getPrimaryTemplate());
134 if (
const auto *Specialization =
135 dyn_cast<ClassTemplateSpecializationDecl>(Used)) {
136 removeFromFoundDecls(Specialization->getSpecializedTemplate());
139 if (
const auto *ECD = dyn_cast<EnumConstantDecl>(Used)) {
140 if (
const auto *ET = ECD->getType()->getAsCanonical<EnumType>())
141 removeFromFoundDecls(ET->getDecl());
146 if (
const auto *Used = Result.Nodes.getNodeAs<NamedDecl>(
"used")) {
147 RemoveNamedDecl(Used);
151 if (
const auto *UsedShadow =
152 Result.Nodes.getNodeAs<UsingShadowDecl>(
"usedShadow")) {
153 removeFromFoundDecls(UsedShadow->getTargetDecl());
157 if (
const auto *Used = Result.Nodes.getNodeAs<TemplateArgument>(
"used")) {
158 if (Used->getKind() == TemplateArgument::Template) {
159 if (
const auto *TD = Used->getAsTemplate().getAsTemplateDecl())
160 removeFromFoundDecls(TD);
164 if (Used->getKind() == TemplateArgument::Type) {
165 if (
auto *RD = Used->getAsType()->getAsCXXRecordDecl())
166 removeFromFoundDecls(RD);
170 if (Used->getKind() == TemplateArgument::Declaration)
171 RemoveNamedDecl(Used->getAsDecl());
175 if (
const auto *DRE = Result.Nodes.getNodeAs<DeclRefExpr>(
"used")) {
176 RemoveNamedDecl(DRE->getDecl());
180 if (
const auto *ULE = Result.Nodes.getNodeAs<UnresolvedLookupExpr>(
"used")) {
181 for (
const NamedDecl *ND : ULE->decls())
182 if (
const auto *USD = dyn_cast<UsingShadowDecl>(ND))
183 removeFromFoundDecls(USD->getTargetDecl()->getCanonicalDecl());
187 if (
const auto *UDL = Result.Nodes.getNodeAs<UserDefinedLiteral>(
"used")) {
188 const Decl *CalleeDecl = UDL->getCalleeDecl();
189 if (
const auto *FD = dyn_cast<FunctionDecl>(CalleeDecl)) {
190 if (
const FunctionTemplateDecl *FPT = FD->getPrimaryTemplate()) {
191 removeFromFoundDecls(FPT);
195 removeFromFoundDecls(CalleeDecl);
Every ClangTidyCheck reports errors through a DiagnosticsEngine provided by this context.