Skip to content

[clang-tidy] Fix false positives with deducing this in readability-convert-member-functions-to-static check #141391

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jun 8, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
4 changes: 4 additions & 0 deletions clang-tools-extra/docs/ReleaseNotes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,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
Expand Down
Original file line number Diff line number Diff line change
@@ -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 &) {}
};
Loading