File tree Expand file tree Collapse file tree 3 files changed +28
-0
lines changed Expand file tree Collapse file tree 3 files changed +28
-0
lines changed Original file line number Diff line number Diff line change @@ -62,6 +62,16 @@ AST_MATCHER(CXXMethodDecl, usesThis) {
6262 return false ; // Stop traversal.
6363 }
6464
65+ bool VisitDeclRefExpr (const DeclRefExpr *E) {
66+ if (const auto *PVD = dyn_cast_if_present<ParmVarDecl>(E->getDecl ());
67+ PVD && PVD->isExplicitObjectParameter ()) {
68+ Used = true ;
69+ return false ; // Stop traversal.
70+ }
71+
72+ return true ;
73+ }
74+
6575 // If we enter a class declaration, don't traverse into it as any usages of
6676 // `this` will correspond to the nested class.
6777 bool TraverseCXXRecordDecl (CXXRecordDecl *RD) { return true ; }
Original file line number Diff line number Diff line change @@ -252,6 +252,10 @@ Changes in existing checks
252252 tolerating fix-it breaking compilation when functions is used as pointers
253253 to avoid matching usage of functions within the current compilation unit.
254254
255+ - Improved :doc: `readability-convert-member-functions-to-static
256+ <clang-tidy/checks/readability/convert-member-functions-to-static>` check by
257+ fixing false positives on member functions with an explicit object parameter.
258+
255259- Improved :doc: `readability-math-missing-parentheses
256260 <clang-tidy/checks/readability/math-missing-parentheses>` check by fixing
257261 false negatives where math expressions are the operand of assignment operators
Original file line number Diff line number Diff line change 1+ // RUN: %check_clang_tidy -std=c++23 %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+ namespace PR141381 {
9+ struct Hello {
10+ std::string str_;
11+
12+ void hello (this Hello &self) { std::println (" Hello, {0}!" , self.str_ ); }
13+ };
14+ }
You can’t perform that action at this time.
0 commit comments