File tree Expand file tree Collapse file tree 3 files changed +24
-0
lines changed Expand file tree Collapse file tree 3 files changed +24
-0
lines changed Original file line number Diff line number Diff line change 8
8
9
9
#include " UnusedUsingDeclsCheck.h"
10
10
#include " clang/AST/ASTContext.h"
11
+ #include " clang/AST/Decl.h"
11
12
#include " clang/ASTMatchers/ASTMatchFinder.h"
12
13
#include " clang/Lex/Lexer.h"
13
14
@@ -71,6 +72,10 @@ void UnusedUsingDeclsCheck::registerMatchers(MatchFinder *Finder) {
71
72
templateArgument ().bind (" used" )))),
72
73
this );
73
74
Finder->addMatcher (userDefinedLiteral ().bind (" used" ), this );
75
+ Finder->addMatcher (
76
+ loc (elaboratedType (unless (hasQualifier (nestedNameSpecifier ())),
77
+ hasUnqualifiedDesugaredType (type ().bind (" usedType" )))),
78
+ this );
74
79
// Cases where we can identify the UsingShadowDecl directly, rather than
75
80
// just its target.
76
81
// FIXME: cover more cases in this way, as the AST supports it.
@@ -145,6 +150,12 @@ void UnusedUsingDeclsCheck::check(const MatchFinder::MatchResult &Result) {
145
150
return ;
146
151
}
147
152
153
+ if (const auto *T = Result.Nodes .getNodeAs <Type>(" usedType" )) {
154
+ if (const auto *ND = T->getAsTagDecl ())
155
+ RemoveNamedDecl (ND);
156
+ return ;
157
+ }
158
+
148
159
if (const auto *UsedShadow =
149
160
Result.Nodes .getNodeAs <UsingShadowDecl>(" usedShadow" )) {
150
161
removeFromFoundDecls (UsedShadow->getTargetDecl ());
Original file line number Diff line number Diff line change @@ -291,6 +291,10 @@ Changes in existing checks
291
291
<clang-tidy/checks/misc/redundant-expression>` check to ignore
292
292
false-positives in unevaluated context (e.g., ``decltype ``).
293
293
294
+ - Improved :doc: `misc-unused-using-decls
295
+ <clang-tidy/checks/misc/unused-using-decls>` check to avoid false positive when
296
+ using in elaborated type.
297
+
294
298
- Improved :doc: `modernize-avoid-bind
295
299
<clang-tidy/checks/modernize/avoid-bind>` check to
296
300
not emit a ``return `` for fixes when the function returns ``void ``.
Original file line number Diff line number Diff line change @@ -213,3 +213,12 @@ template <typename T, template <typename> class U> class Bar {};
213
213
// We used to report Q unsued, because we only checked the first template
214
214
// argument.
215
215
Bar<int , Q> *bar;
216
+
217
+ namespace gh69714 {
218
+ struct StructGH69714_1 {};
219
+ struct StructGH69714_2 {};
220
+ } // namespace gh69714
221
+ using gh69714::StructGH69714_1;
222
+ using gh69714::StructGH69714_2;
223
+ struct StructGH69714_1 a;
224
+ struct StructGH69714_2 *b;
You can’t perform that action at this time.
0 commit comments