PR c++/89705 - ICE with reference binding with conversion function.
authorMarek Polacek <polacek@redhat.com>
Mon, 25 Mar 2019 16:10:06 +0000 (16:10 +0000)
committerMarek Polacek <mpolacek@gcc.gnu.org>
Mon, 25 Mar 2019 16:10:06 +0000 (16:10 +0000)
* call.c (reference_binding): If the result of the conversion function
is a prvalue of non-class type, use the cv-unqualified type.

* g++.dg/cpp0x/rv-conv2.C: New test.

From-SVN: r269918

gcc/cp/ChangeLog
gcc/cp/call.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/cpp0x/rv-conv2.C [new file with mode: 0644]

index 7589b30..b2b7b41 100644 (file)
@@ -1,3 +1,9 @@
+2019-03-25  Marek Polacek  <polacek@redhat.com>
+
+       PR c++/89705 - ICE with reference binding with conversion function.
+       * call.c (reference_binding): If the result of the conversion function
+       is a prvalue of non-class type, use the cv-unqualified type.
+
 2019-03-25  Nathan Sidwell  <nathan@acm.org>
 
        * lambda.c (maybe_add_lambda_conv_op): Don't add to comdat group.
index a4adab2..9efca73 100644 (file)
@@ -1853,6 +1853,9 @@ reference_binding (tree rto, tree rfrom, tree expr, bool c_cast_p, int flags,
            && DECL_CONV_FN_P (t->cand->fn))
          {
            tree ftype = TREE_TYPE (TREE_TYPE (t->cand->fn));
+           /* A prvalue of non-class type is cv-unqualified.  */
+           if (!TYPE_REF_P (ftype) && !CLASS_TYPE_P (ftype))
+             ftype = cv_unqualified (ftype);
            int sflags = (flags|LOOKUP_NO_CONVERSION)&~LOOKUP_NO_TEMP_BIND;
            conversion *new_second
              = reference_binding (rto, ftype, NULL_TREE, c_cast_p,
index 7e1978b..01364a9 100644 (file)
@@ -1,3 +1,8 @@
+2019-03-25  Marek Polacek  <polacek@redhat.com>
+
+       PR c++/89705 - ICE with reference binding with conversion function.
+       * g++.dg/cpp0x/rv-conv2.C: New test.
+
 2019-03-25  Richard Biener  <rguenther@suse.de>
 
        PR tree-optimization/89789
diff --git a/gcc/testsuite/g++.dg/cpp0x/rv-conv2.C b/gcc/testsuite/g++.dg/cpp0x/rv-conv2.C
new file mode 100644 (file)
index 0000000..9b9b154
--- /dev/null
@@ -0,0 +1,18 @@
+// PR c++/89705
+// { dg-do compile { target c++11 } }
+
+struct W { operator const volatile int(); };
+const int& rci = W();
+
+struct X { operator const int(); };
+int&& rri = X();
+
+struct Y { operator volatile int(); };
+int&& rri2 = Y();
+
+struct Z { operator const volatile int(); };
+volatile int&& rri3 = Z();
+
+enum E { A };
+struct S { operator const E(); };
+E&& rre = S();