From 1ee02f9b6053617b741de542ee127c17c5a548be Mon Sep 17 00:00:00 2001 From: cor3ntin Date: Thu, 30 May 2024 17:22:07 +0200 Subject: [PATCH] [Clang] Fix overloading for constrained variadic functions (#93817) Found by #93667 --- clang/docs/ReleaseNotes.rst | 2 ++ clang/lib/Sema/SemaOverload.cpp | 2 +- clang/test/SemaTemplate/concepts.cpp | 22 ++++++++++++++++++++++ 3 files changed, 25 insertions(+), 1 deletion(-) diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index 9dc93f53fe7168..f0cdccfcc3c237 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -816,6 +816,8 @@ Bug Fixes to C++ Support - Fix incorrect merging of modules which contain using declarations which shadow other declarations. This could manifest as ODR checker false positives. Fixes (`#80252 `_) +- Fix a regression introduced in Clang 18 causing incorrect overload resolution in the presence of functions only + differering by their constraints when only one of these function was variadic. Bug Fixes to AST Handling ^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/clang/lib/Sema/SemaOverload.cpp b/clang/lib/Sema/SemaOverload.cpp index 6c5e8afbcfb6ee..6c4ce1022ae274 100644 --- a/clang/lib/Sema/SemaOverload.cpp +++ b/clang/lib/Sema/SemaOverload.cpp @@ -10367,7 +10367,7 @@ static bool sameFunctionParameterTypeLists(Sema &S, FunctionDecl *Fn1 = Cand1.Function; FunctionDecl *Fn2 = Cand2.Function; - if (Fn1->isVariadic() != Fn1->isVariadic()) + if (Fn1->isVariadic() != Fn2->isVariadic()) return false; if (!S.FunctionNonObjectParamTypesAreEqual( diff --git a/clang/test/SemaTemplate/concepts.cpp b/clang/test/SemaTemplate/concepts.cpp index 787cc809e25353..a4b42cad79abd4 100644 --- a/clang/test/SemaTemplate/concepts.cpp +++ b/clang/test/SemaTemplate/concepts.cpp @@ -1122,3 +1122,25 @@ template concept f = c< d >; template struct e; // expected-note {{}} template struct e; // expected-error {{class template partial specialization is not more specialized than the primary template}} } + + +namespace constrained_variadic { +template +struct S { + void f(); // expected-note {{candidate}} + void f(...) requires true; // expected-note {{candidate}} + + void g(...); // expected-note {{candidate}} + void g() requires true; // expected-note {{candidate}} + + consteval void h(...); + consteval void h(...) requires true {}; +}; + +int test() { + S{}.f(); // expected-error{{call to member function 'f' is ambiguous}} + S{}.g(); // expected-error{{call to member function 'g' is ambiguous}} + S{}.h(); +} + +}