[clang] [clang][Sema] Fix tautological type check in sameFunctionParameterTypeLists (PR #224500)

Benji Smith via cfe-commits cfe-commits at lists.llvm.org
Thu Sep 17 19:59:35 PDT 2026


https://github.com/Benjins created https://github.com/llvm/llvm-project/pull/224500

hasSameType had duplicate parameters, which meant we weren't actually checking if the function signatures are equal, so in the case they aren't we could incorrectly accept ambiguous overload resolutions.

Fixes https://github.com/llvm/llvm-project/issues/224499

>From 26146a33855691fc1f1cac84dc1d0ebb8b0411f9 Mon Sep 17 00:00:00 2001
From: Benji Smith <benjsith at gmail.com>
Date: Thu, 17 Sep 2026 21:47:57 -0400
Subject: [PATCH] [clang][Sema] Fix tautological type check in
 sameFunctionParameterTypeLists

hasSameType had duplicate parameters, which meant we weren't actually checking if
the function signatures are equal, so in the case they aren't we could incorrectly
accept ambiguous overload resolutions.

Fixes https://github.com/llvm/llvm-project/issues/224499
---
 clang/lib/Sema/SemaOverload.cpp                  |  2 +-
 .../CXX/over/over.match/over.match.best/p2.cpp   | 16 ++++++++++++++++
 2 files changed, 17 insertions(+), 1 deletion(-)

diff --git a/clang/lib/Sema/SemaOverload.cpp b/clang/lib/Sema/SemaOverload.cpp
index a90c118b682fd..e12b727274408 100644
--- a/clang/lib/Sema/SemaOverload.cpp
+++ b/clang/lib/Sema/SemaOverload.cpp
@@ -10980,7 +10980,7 @@ static bool sameFunctionParameterTypeLists(Sema &S, FunctionDecl *Fn1,
     if (Mem1->isInstance() && Mem2->isInstance() &&
         !S.getASTContext().hasSameType(
             Mem1->getFunctionObjectParameterReferenceType(),
-            Mem1->getFunctionObjectParameterReferenceType()))
+            Mem2->getFunctionObjectParameterReferenceType()))
       return false;
   }
   return true;
diff --git a/clang/test/CXX/over/over.match/over.match.best/p2.cpp b/clang/test/CXX/over/over.match/over.match.best/p2.cpp
index e0f7dfb6a4065..59b545ea637a2 100644
--- a/clang/test/CXX/over/over.match/over.match.best/p2.cpp
+++ b/clang/test/CXX/over/over.match/over.match.best/p2.cpp
@@ -18,3 +18,19 @@ namespace PR44761 {
   // expected-note@#2 {{candidate function has been explicitly deleted}}
   // expected-note@#2 {{candidate function (with reversed parameter order) has been explicitly deleted}}
 }
+
+namespace ambiguous_resolution {
+  template<class T> struct S {
+    int f() const requires true { return 1; } // #S-const-overload
+    int f() volatile { return 2; } // #S-volatile-overload
+  };
+  int test() {
+    // Here, we have two overloads: `const S&` and `volatile S&`
+    // Neither conversion should win the tie-break, and so we should
+    // instead error on ambiguous overloads
+    S<int> s; return s.f();
+    // expected-error at -1 {{call to member function 'f' is ambiguous}}
+    // expected-note@#S-const-overload {{candidate function}}
+    // expected-note@#S-volatile-overload {{candidate function}}
+  }
+}



More information about the cfe-commits mailing list