diff options
author | Nathan James <n.james93@hotmail.co.uk> | 2023-06-24 14:18:20 +0000 |
---|---|---|
committer | Piotr Zegar <me@piotrzegar.pl> | 2023-06-24 14:35:11 +0000 |
commit | 67e05d380c2253319c22451d340e2e3c2043b6d8 (patch) | |
tree | 9bd13d1c5e5f3e583137901ce901a8b7d24e0642 /clang-tools-extra/clang-tidy/readability/ConvertMemberFunctionsToStatic.cpp | |
parent | c35e4cf7ba362e0f2b1c5978bb22bbb9ae955c30 (diff) | |
download | llvm-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/clang-tidy/readability/ConvertMemberFunctionsToStatic.cpp')
-rw-r--r-- | clang-tools-extra/clang-tidy/readability/ConvertMemberFunctionsToStatic.cpp | 5 |
1 files changed, 5 insertions, 0 deletions
diff --git a/clang-tools-extra/clang-tidy/readability/ConvertMemberFunctionsToStatic.cpp b/clang-tools-extra/clang-tidy/readability/ConvertMemberFunctionsToStatic.cpp index 0ef7d29..1284df6 100644 --- a/clang-tools-extra/clang-tidy/readability/ConvertMemberFunctionsToStatic.cpp +++ b/clang-tools-extra/clang-tidy/readability/ConvertMemberFunctionsToStatic.cpp @@ -61,6 +61,11 @@ AST_MATCHER(CXXMethodDecl, usesThis) { Used = true; return false; // Stop traversal. } + + // If we enter a class declaration, don't traverse into it as any usages of + // `this` will correspond to the nested class. + bool TraverseCXXRecordDecl(CXXRecordDecl *RD) { return true; } + } UsageOfThis; // TraverseStmt does not modify its argument. |