[clang-tools-extra] 239c8ac - [clang-tidy] Fix false positives with deducing this in `readability-convert-member-functions-to-static` check (#141391)
via cfe-commits
cfe-commits at lists.llvm.org
Sat Jun 7 23:58:28 PDT 2025
Author: flovent
Date: 2025-06-08T09:58:24+03:00
New Revision: 239c8ac2680fd579a09e27eb2c89ba71ae1fce36
URL: https://github.com/llvm/llvm-project/commit/239c8ac2680fd579a09e27eb2c89ba71ae1fce36
DIFF: https://github.com/llvm/llvm-project/commit/239c8ac2680fd579a09e27eb2c89ba71ae1fce36.diff
LOG: [clang-tidy] Fix false positives with deducing this in `readability-convert-member-functions-to-static` check (#141391)
Add check for `DeclRefExpr` which points to an explicit object
parameter.
Fixes #141381.
---------
Co-authored-by: fubowen <fubowen at protomail.com>
Co-authored-by: flovent <flbven at protomail.com>
Added:
clang-tools-extra/test/clang-tidy/checkers/readability/convert-member-functions-to-static-deducing-this.cpp
Modified:
clang-tools-extra/clang-tidy/readability/ConvertMemberFunctionsToStatic.cpp
clang-tools-extra/docs/ReleaseNotes.rst
Removed:
################################################################################
diff --git a/clang-tools-extra/clang-tidy/readability/ConvertMemberFunctionsToStatic.cpp b/clang-tools-extra/clang-tidy/readability/ConvertMemberFunctionsToStatic.cpp
index 1284df6bd99cf..beca824c8c8ce 100644
--- a/clang-tools-extra/clang-tidy/readability/ConvertMemberFunctionsToStatic.cpp
+++ b/clang-tools-extra/clang-tidy/readability/ConvertMemberFunctionsToStatic.cpp
@@ -81,7 +81,8 @@ void ConvertMemberFunctionsToStatic::registerMatchers(MatchFinder *Finder) {
unless(anyOf(
isExpansionInSystemHeader(), isVirtual(), isStatic(),
hasTrivialBody(), isOverloadedOperator(), cxxConstructorDecl(),
- cxxDestructorDecl(), cxxConversionDecl(), isTemplate(),
+ cxxDestructorDecl(), cxxConversionDecl(),
+ isExplicitObjectMemberFunction(), isTemplate(),
isDependentContext(),
ofClass(anyOf(
isLambda(),
diff --git a/clang-tools-extra/docs/ReleaseNotes.rst b/clang-tools-extra/docs/ReleaseNotes.rst
index 10f6cf670ae16..97f66a18c7c99 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -256,6 +256,10 @@ Changes in existing checks
tolerating fix-it breaking compilation when functions is used as pointers
to avoid matching usage of functions within the current compilation unit.
+- Improved :doc:`readability-convert-member-functions-to-static
+ <clang-tidy/checks/readability/convert-member-functions-to-static>` check by
+ fixing false positives on member functions with an explicit object parameter.
+
- Improved :doc:`readability-math-missing-parentheses
<clang-tidy/checks/readability/math-missing-parentheses>` check by fixing
false negatives where math expressions are the operand of assignment operators
diff --git a/clang-tools-extra/test/clang-tidy/checkers/readability/convert-member-functions-to-static-deducing-this.cpp b/clang-tools-extra/test/clang-tidy/checkers/readability/convert-member-functions-to-static-deducing-this.cpp
new file mode 100644
index 0000000000000..7974301aecce0
--- /dev/null
+++ b/clang-tools-extra/test/clang-tidy/checkers/readability/convert-member-functions-to-static-deducing-this.cpp
@@ -0,0 +1,22 @@
+// RUN: %check_clang_tidy -std=c++23-or-later %s readability-convert-member-functions-to-static %t
+
+namespace std{
+ class string {};
+ void println(const char *format, const std::string &str) {}
+}
+
+struct Hello {
+ std::string str_;
+
+ void ByValueSelf(this Hello self) { std::println("Hello, {0}!", self.str_); }
+
+ void ByLRefSelf(this Hello &self) { std::println("Hello, {0}!", self.str_); }
+
+ void ByRRefSelf(this Hello&& self) {}
+
+ template<typename Self> void ByForwardRefSelf(this Self&& self) {}
+
+ void MultiParam(this Hello &self, int a, double b) {}
+
+ void UnnamedExplicitObjectParam(this Hello &) {}
+};
More information about the cfe-commits
mailing list