public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc(refs/vendors/redhat/heads/gcc-8-branch)] c++: Allow template rvalue-ref conv to bind to lvalue ref.
@ 2020-09-17 16:47 Jakub Jelinek
  0 siblings, 0 replies; only message in thread
From: Jakub Jelinek @ 2020-09-17 16:47 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:fc7b9288e32e28c65db7825dfbaabce31a0d4a06

commit fc7b9288e32e28c65db7825dfbaabce31a0d4a06
Author: Jason Merrill <jason@redhat.com>
Date:   Wed Feb 26 00:33:52 2020 -0500

    c++: Allow template rvalue-ref conv to bind to lvalue ref.
    
    When I implemented the [over.match.ref] rule that a reference conversion
    function needs to match l/rvalue of the target reference type it changed our
    handling of this testcase.  It seems to me that our current behavior is what
    the standard says, but it doesn't seem desirable, and all the other
    compilers have our old behavior.  So let's limit the change to non-templates
    until there's some clarification from the committee.
    
    gcc/cp/ChangeLog
    2020-02-26  Jason Merrill  <jason@redhat.com>
    
            PR c++/90546
            * call.c (build_user_type_conversion_1): Allow a template conversion
            returning an rvalue reference to bind directly to an lvalue.

Diff:
---
 gcc/cp/ChangeLog                      |  6 ++++++
 gcc/cp/call.c                         |  2 ++
 gcc/testsuite/g++.dg/cpp0x/rv-conv3.C | 15 +++++++++++++++
 3 files changed, 23 insertions(+)

diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index 2b13eba5678..1acd99f4a05 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -1,3 +1,9 @@
+2020-02-26  Jason Merrill  <jason@redhat.com>
+
+	PR c++/90546
+	* call.c (build_user_type_conversion_1): Allow a template conversion
+	returning an rvalue reference to bind directly to an lvalue.
+
 2020-02-26  Jason Merrill  <jason@redhat.com>
 
 	PR c++/86521 - wrong overload resolution with ref-qualifiers.
diff --git a/gcc/cp/call.c b/gcc/cp/call.c
index dffae0efb5e..2f575620b25 100644
--- a/gcc/cp/call.c
+++ b/gcc/cp/call.c
@@ -3896,6 +3896,8 @@ build_user_type_conversion_1 (tree totype, tree expr, int flags,
 						       rettype, totype);
 	    }
 	  else if (TYPE_REF_P (totype) && !ics->rvaluedness_matches_p
+		   /* Limit this to non-templates for now (PR90546).  */
+		   && !cand->template_decl
 		   && TREE_CODE (TREE_TYPE (totype)) != FUNCTION_TYPE)
 	    {
 	      /* If we are called to convert to a reference type, we are trying
diff --git a/gcc/testsuite/g++.dg/cpp0x/rv-conv3.C b/gcc/testsuite/g++.dg/cpp0x/rv-conv3.C
new file mode 100644
index 00000000000..5f727fcc0d5
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/rv-conv3.C
@@ -0,0 +1,15 @@
+// PR c++/90546
+// { dg-do link { target c++11 } }
+
+struct Foo { };
+void test(const Foo&) {}
+Foo f;
+struct Bar {
+  template <class T> operator T&&();
+};
+template<> Bar::operator const Foo&&() {
+    return static_cast<Foo&&>(f);
+}
+int main() {
+  test(Bar{});
+}


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2020-09-17 16:47 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-09-17 16:47 [gcc(refs/vendors/redhat/heads/gcc-8-branch)] c++: Allow template rvalue-ref conv to bind to lvalue ref Jakub Jelinek

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).