Skip to content

Commit 094584c

Browse files
committed
[clang-tidy] Fix invalid fixit for readability-static-accessed-through-instance (bug 40544)
Summary: Fixed https://bugs.llvm.org/show_bug.cgi?id=40544 Before, we would generate a fixit like `(anonymous namespace)::Foo::fun();` for the added test case. Reviewers: aaron.ballman, alexfh, xazax.hun Subscribers: rnkovacs, cfe-commits Tags: #clang, #clang-tools-extra Differential Revision: https://reviews.llvm.org/D61874 llvm-svn: 360698
1 parent 80c6e79 commit 094584c

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

clang-tools-extra/clang-tidy/readability/StaticAccessedThroughInstanceCheck.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ void StaticAccessedThroughInstanceCheck::check(
6767
const ASTContext *AstContext = Result.Context;
6868
PrintingPolicy PrintingPolicyWithSupressedTag(AstContext->getLangOpts());
6969
PrintingPolicyWithSupressedTag.SuppressTagKeyword = true;
70+
PrintingPolicyWithSupressedTag.SuppressUnwrittenScope = true;
7071
std::string BaseTypeName =
7172
BaseType.getAsString(PrintingPolicyWithSupressedTag);
7273

clang-tools-extra/test/clang-tidy/readability-static-accessed-through-instance.cpp

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,3 +220,31 @@ int func(Qptr qp) {
220220
qp->y = 10; // OK, the overloaded operator might have side-effects.
221221
qp->K = 10; //
222222
}
223+
224+
namespace {
225+
struct Anonymous {
226+
static int I;
227+
};
228+
}
229+
230+
void use_anonymous() {
231+
Anonymous Anon;
232+
Anon.I;
233+
// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: static member
234+
// CHECK-FIXES: {{^}} Anonymous::I;{{$}}
235+
}
236+
237+
namespace Outer {
238+
inline namespace Inline {
239+
struct S {
240+
static int I;
241+
};
242+
}
243+
}
244+
245+
void use_inline() {
246+
Outer::S V;
247+
V.I;
248+
// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: static member
249+
// CHECK-FIXES: {{^}} Outer::S::I;{{$}}
250+
}

0 commit comments

Comments
 (0)