Skip to content

Commit 239c8ac

Browse files
floventfubowenflovent
authored
[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 <[email protected]> Co-authored-by: flovent <[email protected]>
1 parent 532facc commit 239c8ac

File tree

3 files changed

+28
-1
lines changed

3 files changed

+28
-1
lines changed

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,8 @@ void ConvertMemberFunctionsToStatic::registerMatchers(MatchFinder *Finder) {
8181
unless(anyOf(
8282
isExpansionInSystemHeader(), isVirtual(), isStatic(),
8383
hasTrivialBody(), isOverloadedOperator(), cxxConstructorDecl(),
84-
cxxDestructorDecl(), cxxConversionDecl(), isTemplate(),
84+
cxxDestructorDecl(), cxxConversionDecl(),
85+
isExplicitObjectMemberFunction(), isTemplate(),
8586
isDependentContext(),
8687
ofClass(anyOf(
8788
isLambda(),

clang-tools-extra/docs/ReleaseNotes.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,10 @@ Changes in existing checks
256256
tolerating fix-it breaking compilation when functions is used as pointers
257257
to avoid matching usage of functions within the current compilation unit.
258258

259+
- Improved :doc:`readability-convert-member-functions-to-static
260+
<clang-tidy/checks/readability/convert-member-functions-to-static>` check by
261+
fixing false positives on member functions with an explicit object parameter.
262+
259263
- Improved :doc:`readability-math-missing-parentheses
260264
<clang-tidy/checks/readability/math-missing-parentheses>` check by fixing
261265
false negatives where math expressions are the operand of assignment operators
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// RUN: %check_clang_tidy -std=c++23-or-later %s readability-convert-member-functions-to-static %t
2+
3+
namespace std{
4+
class string {};
5+
void println(const char *format, const std::string &str) {}
6+
}
7+
8+
struct Hello {
9+
std::string str_;
10+
11+
void ByValueSelf(this Hello self) { std::println("Hello, {0}!", self.str_); }
12+
13+
void ByLRefSelf(this Hello &self) { std::println("Hello, {0}!", self.str_); }
14+
15+
void ByRRefSelf(this Hello&& self) {}
16+
17+
template<typename Self> void ByForwardRefSelf(this Self&& self) {}
18+
19+
void MultiParam(this Hello &self, int a, double b) {}
20+
21+
void UnnamedExplicitObjectParam(this Hello &) {}
22+
};

0 commit comments

Comments
 (0)