58 Finder->addMatcher(usingDecl(isExpansionInMainFile()).bind(
"using"),
this);
59 const 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 const auto ThroughShadowMatcher =
79 throughUsingDecl(namedDecl().bind(
"usedShadow"));
80 Finder->addMatcher(declRefExpr(ThroughShadowMatcher),
this);
81 Finder->addMatcher(loc(usingType(ThroughShadowMatcher)),
this);
85 if (Result.Context->getDiagnostics().hasUncompilableErrorOccurred())
88 if (
const auto *Using = Result.Nodes.getNodeAs<UsingDecl>(
"using")) {
90 if (Using->getLocation().isMacroID())
94 if (isa<CXXRecordDecl>(Using->getDeclContext()))
100 if (isa<FunctionDecl>(Using->getDeclContext()))
104 if (Using->hasOwningModule() &&
105 Using->getModuleOwnershipKind() <=
106 Decl::ModuleOwnershipKind::VisibleWhenImported)
109 UsingDeclContext Context(Using);
110 Context.UsingDeclRange = CharSourceRange::getCharRange(
111 Using->getBeginLoc(),
112 Lexer::findLocationAfterToken(
113 Using->getEndLoc(), tok::semi, *Result.SourceManager, getLangOpts(),
115 for (
const auto *UsingShadow : Using->shadows()) {
116 const auto *TargetDecl = UsingShadow->getTargetDecl()->getCanonicalDecl();
118 Context.UsingTargetDecls.insert(TargetDecl);
119 UsingTargetDeclsCache.insert(TargetDecl);
122 if (!Context.UsingTargetDecls.empty())
123 Contexts.push_back(Context);
128 const auto RemoveNamedDecl = [&](
const NamedDecl *Used) {
129 removeFromFoundDecls(Used);
131 if (
const auto *FD = dyn_cast<FunctionDecl>(Used)) {
132 removeFromFoundDecls(FD->getPrimaryTemplate());
135 if (
const auto *Specialization =
136 dyn_cast<ClassTemplateSpecializationDecl>(Used)) {
137 removeFromFoundDecls(Specialization->getSpecializedTemplate());
140 if (
const auto *ECD = dyn_cast<EnumConstantDecl>(Used)) {
141 if (
const auto *ET = ECD->getType()->getAsCanonical<EnumType>())
142 removeFromFoundDecls(ET->getDecl());
147 if (
const auto *Used = Result.Nodes.getNodeAs<NamedDecl>(
"used")) {
148 RemoveNamedDecl(Used);
152 if (
const auto *UsedShadow =
153 Result.Nodes.getNodeAs<UsingShadowDecl>(
"usedShadow")) {
154 removeFromFoundDecls(UsedShadow->getTargetDecl());
158 if (
const auto *Used = Result.Nodes.getNodeAs<TemplateArgument>(
"used")) {
159 if (Used->getKind() == TemplateArgument::Template) {
160 if (
const auto *TD = Used->getAsTemplate().getAsTemplateDecl())
161 removeFromFoundDecls(TD);
165 if (Used->getKind() == TemplateArgument::Type) {
166 if (
const auto *RD = Used->getAsType()->getAsCXXRecordDecl())
167 removeFromFoundDecls(RD);
171 if (Used->getKind() == TemplateArgument::Declaration)
172 RemoveNamedDecl(Used->getAsDecl());
176 if (
const auto *DRE = Result.Nodes.getNodeAs<DeclRefExpr>(
"used")) {
177 RemoveNamedDecl(DRE->getDecl());
181 if (
const auto *ULE = Result.Nodes.getNodeAs<UnresolvedLookupExpr>(
"used")) {
182 for (
const NamedDecl *ND : ULE->decls())
183 if (
const auto *USD = dyn_cast<UsingShadowDecl>(ND))
184 removeFromFoundDecls(USD->getTargetDecl()->getCanonicalDecl());
188 if (
const auto *UDL = Result.Nodes.getNodeAs<UserDefinedLiteral>(
"used")) {
189 const Decl *CalleeDecl = UDL->getCalleeDecl();
190 if (
const auto *FD = dyn_cast<FunctionDecl>(CalleeDecl)) {
191 if (
const FunctionTemplateDecl *FPT = FD->getPrimaryTemplate()) {
192 removeFromFoundDecls(FPT);
196 removeFromFoundDecls(CalleeDecl);
Every ClangTidyCheck reports errors through a DiagnosticsEngine provided by this context.