@@ -23,6 +23,7 @@ void UnusedUsingDeclsCheck::registerMatchers(MatchFinder *Finder) {
23
23
auto DeclMatcher = hasDeclaration (namedDecl ().bind (" used" ));
24
24
Finder->addMatcher (loc (recordType (DeclMatcher)), this );
25
25
Finder->addMatcher (loc (templateSpecializationType (DeclMatcher)), this );
26
+ Finder->addMatcher (declRefExpr ().bind (" used" ), this );
26
27
}
27
28
28
29
void UnusedUsingDeclsCheck::check (const MatchFinder::MatchResult &Result) {
@@ -34,8 +35,13 @@ void UnusedUsingDeclsCheck::check(const MatchFinder::MatchResult &Result) {
34
35
const auto *TargetDecl =
35
36
Using->shadow_begin ()->getTargetDecl ()->getCanonicalDecl ();
36
37
37
- // FIXME: Handle other target types.
38
- if (!isa<RecordDecl>(TargetDecl) && !isa<ClassTemplateDecl>(TargetDecl))
38
+ // Ignores using-declarations defined in class definition.
39
+ if (isa<CXXRecordDecl>(TargetDecl->getDeclContext ()))
40
+ return ;
41
+
42
+ if (!isa<RecordDecl>(TargetDecl) && !isa<ClassTemplateDecl>(TargetDecl) &&
43
+ !isa<FunctionDecl>(TargetDecl) && !isa<VarDecl>(TargetDecl) &&
44
+ !isa<FunctionTemplateDecl>(TargetDecl))
39
45
return ;
40
46
41
47
FoundDecls[TargetDecl] = Using;
@@ -57,10 +63,26 @@ void UnusedUsingDeclsCheck::check(const MatchFinder::MatchResult &Result) {
57
63
if (const auto *Specialization =
58
64
dyn_cast<ClassTemplateSpecializationDecl>(Used))
59
65
Used = Specialization->getSpecializedTemplate ();
60
- auto I = FoundDecls.find (Used->getCanonicalDecl ());
61
- if (I != FoundDecls.end ())
62
- I->second = nullptr ;
66
+ removeFromFoundDecls (Used);
67
+ return ;
63
68
}
69
+
70
+ if (const auto *DRE = Result.Nodes .getNodeAs <DeclRefExpr>(" used" )) {
71
+ if (const auto *FD = dyn_cast<FunctionDecl>(DRE->getDecl ())) {
72
+ if (const auto *FDT = FD->getPrimaryTemplate ())
73
+ removeFromFoundDecls (FDT);
74
+ else
75
+ removeFromFoundDecls (FD);
76
+ } else if (const auto *VD = dyn_cast<VarDecl>(DRE->getDecl ())) {
77
+ removeFromFoundDecls (VD);
78
+ }
79
+ }
80
+ }
81
+
82
+ void UnusedUsingDeclsCheck::removeFromFoundDecls (const Decl *D) {
83
+ auto I = FoundDecls.find (D->getCanonicalDecl ());
84
+ if (I != FoundDecls.end ())
85
+ I->second = nullptr ;
64
86
}
65
87
66
88
void UnusedUsingDeclsCheck::onEndOfTranslationUnit () {
0 commit comments