[clang-tools-extra] [clang-tidy] Overloaded Unresolved member function call can't be static (PR #191432)

Gaurav Dhingra via cfe-commits cfe-commits at lists.llvm.org
Wed Apr 22 02:37:02 PDT 2026


https://github.com/gxyd updated https://github.com/llvm/llvm-project/pull/191432

>From 53379153367e36adf2bb8a36088b78ba6d65ede2 Mon Sep 17 00:00:00 2001
From: Gaurav Dhingra <gauravdhingra.gxyd at gmail.com>
Date: Fri, 10 Apr 2026 19:55:21 +0530
Subject: [PATCH 1/4] [clang-tidy] Unresolve member function call can't be
 static

readability-convert-member-functions-to-static incorrectly suggests
making overloaded member function, with lambda function call, as
static (false-positive)

Mark usage of "this" as true, when a call to "UnresolveMemberExpr"
is obvserved

Fixes #171626
---
 .../readability/ConvertMemberFunctionsToStaticCheck.cpp      | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/clang-tools-extra/clang-tidy/readability/ConvertMemberFunctionsToStaticCheck.cpp b/clang-tools-extra/clang-tidy/readability/ConvertMemberFunctionsToStaticCheck.cpp
index 40952b2fc9d0c..8b0debc78bb77 100644
--- a/clang-tools-extra/clang-tidy/readability/ConvertMemberFunctionsToStaticCheck.cpp
+++ b/clang-tools-extra/clang-tidy/readability/ConvertMemberFunctionsToStaticCheck.cpp
@@ -64,6 +64,11 @@ AST_MATCHER(CXXMethodDecl, usesThis) {
       return false; // Stop traversal.
     }
 
+    bool VisitUnresolvedMemberExpr(const UnresolvedMemberExpr *E) {
+      Used = true;
+      return false;
+    }
+
     // 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; }

>From 4087cf9ee29ed167c839c2f4f3cdfc4a68dc3ceb Mon Sep 17 00:00:00 2001
From: Gaurav Dhingra <gauravdhingra.gxyd at gmail.com>
Date: Fri, 10 Apr 2026 20:07:06 +0530
Subject: [PATCH 2/4] add tests for overloaded unresolve with lambda call

---
 ...mber-functions-to-static-deducing-this.cpp | 24 +++++++++++++++++++
 1 file changed, 24 insertions(+)

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
index a6ca86dd7cefa..790c8f0f927cc 100644
--- 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
@@ -20,3 +20,27 @@ struct Hello {
 
   void UnnamedExplicitObjectParam(this Hello &) {}
 };
+
+
+class OverloadedUnresolvedWithAutoLambda {
+public:
+  void CallsFunctionVar();
+  void CallsOverloadedMethodWithArg(int a);
+  void OverloadedMethodWithoutArg();
+  void OverloadedMethodWithArg(int a) { };
+};
+
+void OverloadedUnresolvedWithAutoLambda::CallsFunctionVar() {
+  // CHECK-MESSAGES: :[[@LINE-1]]:42: warning: method 'CallsFunctionVar' can be made static [readability-convert-member-functions-to-static]
+  auto fun = [&](auto a) {
+    var(a);
+  };
+}
+
+void OverloadedUnresolvedWithAutoLambda::CallsOverloadedMethodWithArg(int a) {
+  auto fun = [&](auto b) {
+    OverloadedMethodWithArg(b);
+  };
+}
+
+void Var(int a) { }

>From 7e4383da88de69547ca3092d1e375defd001db05 Mon Sep 17 00:00:00 2001
From: Gaurav Dhingra <gauravdhingra.gxyd at gmail.com>
Date: Sun, 12 Apr 2026 21:16:37 +0530
Subject: [PATCH 3/4] add ReleaseNotes entry

---
 clang-tools-extra/docs/ReleaseNotes.rst | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/clang-tools-extra/docs/ReleaseNotes.rst b/clang-tools-extra/docs/ReleaseNotes.rst
index f70bf9e9f9eb8..0bf56708f2f92 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -480,6 +480,11 @@ Changes in existing checks
   avoiding false positive on ``const`` member functions to static when they are
   a part of const/non-const overload pair.
 
+- Improved :doc:`readability-convert-member-functions-to-static
+  <clang-tidy/checks/readability/convert-member-functions-to-static>` check to
+  correctly detect ``this`` usage within a member function with a call to an
+  overloaded method inside a generic lambda.
+
 - Improved :doc:`readability-else-after-return
   <clang-tidy/checks/readability/else-after-return>` check:
 

>From 914e34f844529ed26995a53ad5d4902a1e9bc123 Mon Sep 17 00:00:00 2001
From: Gaurav Dhingra <gauravdhingra.gxyd at gmail.com>
Date: Wed, 22 Apr 2026 15:05:57 +0530
Subject: [PATCH 4/4] split release notes entries and improve grammar

used claude AI to help improve the grammar and I've ensured that it
does look technically correct
---
 clang-tools-extra/docs/ReleaseNotes.rst | 13 ++++++-------
 1 file changed, 6 insertions(+), 7 deletions(-)

diff --git a/clang-tools-extra/docs/ReleaseNotes.rst b/clang-tools-extra/docs/ReleaseNotes.rst
index 0bf56708f2f92..10a8249d318f3 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -476,14 +476,13 @@ Changes in existing checks
     ``empty`` function.
 
 - Improved :doc:`readability-convert-member-functions-to-static
-  <clang-tidy/checks/readability/convert-member-functions-to-static>` check by
-  avoiding false positive on ``const`` member functions to static when they are
-  a part of const/non-const overload pair.
+  <clang-tidy/checks/readability/convert-member-functions-to-static>` check:
 
-- Improved :doc:`readability-convert-member-functions-to-static
-  <clang-tidy/checks/readability/convert-member-functions-to-static>` check to
-  correctly detect ``this`` usage within a member function with a call to an
-  overloaded method inside a generic lambda.
+  - Fixing a false positive where ``const`` member functions were incorrectly
+    flagged when they are part of a const/non-const overload pair.
+
+  - Correctly detecting ``this`` usage when a generic lambda calls an overloaded
+    member function.
 
 - Improved :doc:`readability-else-after-return
   <clang-tidy/checks/readability/else-after-return>` check:



More information about the cfe-commits mailing list