https://github.com/zyn0217 created 
https://github.com/llvm/llvm-project/pull/237716

Reverts llvm/llvm-project#233482

It broke some valid code as reported in 
https://github.com/llvm/llvm-project/pull/233482#issuecomment-6556714067

>From 661704166f5dc7cfcf9a80d3caca7f97c9e06aac Mon Sep 17 00:00:00 2001
From: Younan Zhang <[email protected]>
Date: Sun, 1 Nov 2026 19:42:56 +0800
Subject: [PATCH] =?UTF-8?q?Revert=20"[Clang][Sema]=20Fix=20rejecting=20val?=
 =?UTF-8?q?id=20reference=20initialization=20with=20conve=E2=80=A6"?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

This reverts commit da827529a7feda3e8b6279835d839ba3bd8afdd2.
---
 clang/docs/ReleaseNotes.md                   |  3 ---
 clang/lib/Sema/SemaInit.cpp                  |  7 +++----
 clang/test/SemaCXX/conversion-function.cpp   | 13 -------------
 clang/test/SemaCXX/cxx1y-generic-lambdas.cpp |  4 +---
 4 files changed, 4 insertions(+), 23 deletions(-)

diff --git a/clang/docs/ReleaseNotes.md b/clang/docs/ReleaseNotes.md
index a2ad6d06815c7c..d2df8fe262fbff 100644
--- a/clang/docs/ReleaseNotes.md
+++ b/clang/docs/ReleaseNotes.md
@@ -897,9 +897,6 @@ documentation](CIR/index.md) for more information regarding 
ClangIR's status and
   `sized_by_or_null` describe the size in bytes rather than a count of 
elements,
   they are now correctly accepted on such pointers.
 
-- Fixed rejecting valid reference initialization with conversion function 
templates whose returned type is depending on 
-  template parameters. (#GH226984)
-
 - Fixed a crash when an `address_space` attribute with a dependent argument was
   written after the declarator-id, where it appertains to the declared entity
   rather than to a declarator chunk. (#GH196982, #GH111463)
diff --git a/clang/lib/Sema/SemaInit.cpp b/clang/lib/Sema/SemaInit.cpp
index d9134c052fa9df..2e3c6309fec20e 100644
--- a/clang/lib/Sema/SemaInit.cpp
+++ b/clang/lib/Sema/SemaInit.cpp
@@ -5384,13 +5384,12 @@ static OverloadingResult 
TryRefInitWithConversionFunction(
 
       // If the conversion function doesn't return a reference type,
       // it can't be considered for this conversion unless we're allowed to
-      // consider rvalues. If it's a template, we should accept it first
-      // and specialize it before deciding whether to reject it.
+      // consider rvalues.
       // FIXME: Do we need to make sure that we only consider conversion
       // candidates with reference-compatible results? That might be needed to
       // break recursion.
-      if (ConvTemplate || AllowRValues ||
-          Conv->getConversionType()->isLValueReferenceType()) {
+      if ((AllowRValues ||
+           Conv->getConversionType()->isLValueReferenceType())) {
         if (ConvTemplate)
           S.AddTemplateConversionCandidate(
               ConvTemplate, I.getPair(), ActingDC, Initializer, DestType,
diff --git a/clang/test/SemaCXX/conversion-function.cpp 
b/clang/test/SemaCXX/conversion-function.cpp
index 629c818b89c004..1a09a527b750cc 100644
--- a/clang/test/SemaCXX/conversion-function.cpp
+++ b/clang/test/SemaCXX/conversion-function.cpp
@@ -557,16 +557,3 @@ namespace GH189146 {
   int s = S{}(0); // expected-error {{attempt to use a deleted function}}
 }
 #endif
-
-#if __cplusplus >= 201402L
-namespace GH226984 {
-  struct A {
-       int& ref;
-
-       template<int dependent = 0>
-       operator decltype(dependent, ref)();
-};
-  int x = 0;
-  int& y = A(x);
-}
-#endif
diff --git a/clang/test/SemaCXX/cxx1y-generic-lambdas.cpp 
b/clang/test/SemaCXX/cxx1y-generic-lambdas.cpp
index bb621666319046..3066bb0d0f0cc3 100644
--- a/clang/test/SemaCXX/cxx1y-generic-lambdas.cpp
+++ b/clang/test/SemaCXX/cxx1y-generic-lambdas.cpp
@@ -214,9 +214,7 @@ namespace conversion_operator {
   void test() {
     auto L = [](auto a) -> int { return a; }; // expected-error {{cannot 
initialize}}
     int (*fp)(int) = L;
-    int (&fp2)(int) = [](auto a) { return a; };
-    // expected-error@-1   {{no viable conversion}}
-    // expected-note-re@-2 {{candidate template ignored: could not match 'auto 
(*)(auto){{.*}}' against 'int (int)'}}
+    int (&fp2)(int) = [](auto a) { return a; };  // expected-error{{non-const 
lvalue}}
     int (&&fp3)(int) = [](auto a) { return a; };
     // expected-error@-1   {{no viable conversion}}
     // expected-note-re@-2 {{candidate template ignored: could not match 'auto 
(*)(auto){{.*}}' against 'int (int)'}}

_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to