File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -99,6 +99,12 @@ void UnusedUsingDeclsCheck::check(const MatchFinder::MatchResult &Result) {
9999 if (isa<FunctionDecl>(Using->getDeclContext ()))
100100 return ;
101101
102+ // Ignore exported using-decls.
103+ if (Using->hasOwningModule () &&
104+ Using->getModuleOwnershipKind () <=
105+ Decl::ModuleOwnershipKind::VisibleWhenImported)
106+ return ;
107+
102108 UsingDeclContext Context (Using);
103109 Context.UsingDeclRange = CharSourceRange::getCharRange (
104110 Using->getBeginLoc (),
Original file line number Diff line number Diff line change @@ -220,6 +220,10 @@ Changes in existing checks
220220 - Fixed false positive where an array of pointers to ``const `` was
221221 incorrectly diagnosed as allowing the pointee to be made ``const ``.
222222
223+ - Improved :doc: `misc-unused-using-decls
224+ <clang-tidy/checks/misc/unused-using-decls>` to not diagnose ``using ``
225+ declarations as unused if they're exported from a module.
226+
223227- Improved :doc: `modernize-pass-by-value
224228 <clang-tidy/checks/modernize/pass-by-value>` check by adding `IgnoreMacros `
225229 option to suppress warnings in macros.
Original file line number Diff line number Diff line change 1+ // RUN: %check_clang_tidy -std=c++20-or-later %s misc-unused-using-decls %t -- --fix-notes
2+
3+ module ;
4+
5+ namespace n {
6+
7+ struct S {};
8+
9+ } // namespace n
10+
11+ using n::S; // n::S
12+ // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: using decl 'S' is unused
13+ // CHECK-FIXES: // n::S
14+
15+ export module foo;
16+
17+ struct A {};
18+ export struct B {};
19+ export struct C {};
20+ export struct D {};
21+
22+ namespace ns1 {
23+
24+ using ::A; // ns1::A
25+ // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: using decl 'A' is unused
26+ // CHECK-FIXES: // ns1::A
27+
28+ // If the decl isn't exported, it's unused, even if the underlying struct is exported.
29+ using ::B; // ns1::B
30+ // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: using decl 'B' is unused
31+ // CHECK-FIXES: // ns1::B
32+
33+ export using ::C;
34+
35+ export {
36+
37+ using ::D;
38+
39+ }
40+
41+ } // namespace n
42+
43+ export namespace ns2 {
44+
45+ using ::B;
46+
47+ } // namespace ns2
48+
49+ export {
50+
51+ namespace ns3 {
52+
53+ using ::B;
54+
55+ } // namespace ns3
56+
57+ }
58+
59+ export namespace ns3 {
60+
61+ struct E {};
62+
63+ } // namespace ns3
64+
65+ module :private;
66+
67+ using ns3::E; // ns3::E
68+ // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: using decl 'E' is unused
69+ // CHECK-FIXES: // ns3::E
You can’t perform that action at this time.
0 commit comments