PR c++/85215 - ICE with copy-init from conversion.
authorJason Merrill <jason@redhat.com>
Thu, 5 Apr 2018 04:01:15 +0000 (00:01 -0400)
committerJason Merrill <jason@gcc.gnu.org>
Thu, 5 Apr 2018 04:01:15 +0000 (00:01 -0400)
* call.c (merge_conversion_sequences): Fix type of direct binding
sequence.

From-SVN: r259123

gcc/cp/ChangeLog
gcc/cp/call.c
gcc/testsuite/g++.dg/cpp1z/elide3.C [new file with mode: 0644]

index 22f3e42f0cb66ece2c51050b6f1a55c0dfebebdd..fd33f00f8d1d440ce46ba95824f313685a7dfcd5 100644 (file)
@@ -1,5 +1,9 @@
 2018-04-04  Jason Merrill  <jason@redhat.com>
 
+       PR c++/85215 - ICE with copy-init from conversion.
+       * call.c (merge_conversion_sequences): Fix type of direct binding
+       sequence.
+
        PR c++/84938 - ICE with division by ~-1.
        * call.c (set_up_extended_ref_temp): Call cp_fully_fold.
 
index 7c99e8ad9100e9d923caaf5895438345b27b926d..f2ada2768de726565110b8aa94533638f71feee3 100644 (file)
@@ -3642,6 +3642,12 @@ merge_conversion_sequences (conversion *user_seq, conversion *std_seq)
        (*t)->bad_p = true;
     }
 
+  if ((*t)->rvaluedness_matches_p)
+    /* We're binding a reference directly to the result of the conversion.
+       build_user_type_conversion_1 stripped the REFERENCE_TYPE from the return
+       type, but we want it back.  */
+    user_seq->type = TREE_TYPE (TREE_TYPE (user_seq->cand->fn));
+
   /* Replace the identity conversion with the user conversion
      sequence.  */
   *t = user_seq;
diff --git a/gcc/testsuite/g++.dg/cpp1z/elide3.C b/gcc/testsuite/g++.dg/cpp1z/elide3.C
new file mode 100644 (file)
index 0000000..ca4d247
--- /dev/null
@@ -0,0 +1,15 @@
+// PR c++/85215
+// { dg-do compile { target c++11 } }
+
+template <typename _Tp> struct vector {
+  vector(vector &&) noexcept;
+};
+
+template <typename T> struct any_container {
+  operator vector<T> &&();
+};
+
+void f (any_container<int> c)
+{
+  vector<int> shape (c);
+}