From 67e05d380c2253319c22451d340e2e3c2043b6d8 Mon Sep 17 00:00:00 2001 From: Nathan James Date: Sat, 24 Jun 2023 14:18:20 +0000 Subject: [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 --- .../clang-tidy/readability/ConvertMemberFunctionsToStatic.cpp | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'clang-tools-extra/clang-tidy/readability/ConvertMemberFunctionsToStatic.cpp') 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. -- cgit v1.1