[llvm-branch-commits] [clang] 6617041 - Revert "[Clang][Sema] Fix rejecting valid reference initialization with conve…"

via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Sun Nov 1 03:43:00 PST 2026


Author: Younan Zhang
Date: 2026-11-01T19:42:56+08:00
New Revision: 661704166f5dc7cfcf9a80d3caca7f97c9e06aac

URL: https://github.com/llvm/llvm-project/commit/661704166f5dc7cfcf9a80d3caca7f97c9e06aac
DIFF: https://github.com/llvm/llvm-project/commit/661704166f5dc7cfcf9a80d3caca7f97c9e06aac.diff

LOG: Revert "[Clang][Sema] Fix rejecting valid reference initialization with conve…"

This reverts commit da827529a7feda3e8b6279835d839ba3bd8afdd2.

Added: 
    

Modified: 
    clang/docs/ReleaseNotes.md
    clang/lib/Sema/SemaInit.cpp
    clang/test/SemaCXX/conversion-function.cpp
    clang/test/SemaCXX/cxx1y-generic-lambdas.cpp

Removed: 
    


################################################################################
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 at -1   {{no viable conversion}}
-    // expected-note-re at -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 at -1   {{no viable conversion}}
     // expected-note-re at -2 {{candidate template ignored: could not match 'auto (*)(auto){{.*}}' against 'int (int)'}}


        


More information about the llvm-branch-commits mailing list