aboutsummaryrefslogtreecommitdiff
path: root/clang-tools-extra/test
diff options
context:
space:
mode:
authorNathan James <n.james93@hotmail.co.uk>2023-06-24 14:18:20 +0000
committerPiotr Zegar <me@piotrzegar.pl>2023-06-24 14:35:11 +0000
commit67e05d380c2253319c22451d340e2e3c2043b6d8 (patch)
tree9bd13d1c5e5f3e583137901ce901a8b7d24e0642 /clang-tools-extra/test
parentc35e4cf7ba362e0f2b1c5978bb22bbb9ae955c30 (diff)
downloadllvm-67e05d380c2253319c22451d340e2e3c2043b6d8.zip
llvm-67e05d380c2253319c22451d340e2e3c2043b6d8.tar.gz
llvm-67e05d380c2253319c22451d340e2e3c2043b6d8.tar.bz2
[clang-tidy] Fix false negative in readability-convert-member-functions-to-static
A nested class in a member function can erroneously confuse the check into thinking that any CXXThisExpr found relate to the outer class, preventing any warnings. Fix this by not traversing any nested classes. Fixes https://github.com/llvm/llvm-project/issues/56765 Reviewed By: PiotrZSL Differential Revision: https://reviews.llvm.org/D130665
Diffstat (limited to 'clang-tools-extra/test')
-rw-r--r--clang-tools-extra/test/clang-tidy/checkers/readability/convert-member-functions-to-static.cpp18
1 files changed, 18 insertions, 0 deletions
diff --git a/clang-tools-extra/test/clang-tidy/checkers/readability/convert-member-functions-to-static.cpp b/clang-tools-extra/test/clang-tidy/checkers/readability/convert-member-functions-to-static.cpp
index 9612fa9..5ec1f221 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/readability/convert-member-functions-to-static.cpp
+++ b/clang-tools-extra/test/clang-tidy/checkers/readability/convert-member-functions-to-static.cpp
@@ -45,6 +45,24 @@ class A {
static_field = 1;
}
+ void static_nested() {
+ // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: method 'static_nested' can be made static
+ // CHECK-FIXES: {{^}} static void static_nested() {
+ struct Nested {
+ int Foo;
+ int getFoo() { return Foo; }
+ };
+ }
+
+ void write_nested() {
+ struct Nested {
+ int Foo;
+ int getFoo() { return Foo; }
+ };
+ // Ensure we still detect usages of `this` once we leave the nested class definition.
+ field = 1;
+ }
+
static int already_static() { return static_field; }
int already_const() const { return field; }