]> gcc.gnu.org Git - gcc.git/commitdiff
re PR c++/66515 (g++ segfaults when creating an std::initializer_list)
authorJason Merrill <jason@redhat.com>
Wed, 17 Jun 2015 20:45:32 +0000 (16:45 -0400)
committerJason Merrill <jason@gcc.gnu.org>
Wed, 17 Jun 2015 20:45:32 +0000 (16:45 -0400)
PR c++/66515
* call.c (implicit_conversion): Call reshape_init here, early.
(build_aggr_conv): Not here.

From-SVN: r224581

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

index 010442fadfd2bf17238dd935b1e53375835c0782..0ebce1920a17c723c62077da0be213c78f41a0f9 100644 (file)
@@ -1,3 +1,9 @@
+2015-06-17  Jason Merrill  <jason@redhat.com>
+
+       PR c++/66515
+       * call.c (implicit_conversion): Call reshape_init here, early.
+       (build_aggr_conv): Not here.
+
 2015-06-17  Jakub Jelinek  <jakub@redhat.com>
 
        PR c++/66571
index d4da80a4ad82f246a26cc11a25c1aef1fff863c5..5d1891d2c15b7510ef0e23f326caf6d5bfb11342 100644 (file)
@@ -868,9 +868,7 @@ build_aggr_conv (tree type, tree ctor, int flags, tsubst_flags_t complain)
   tree field = next_initializable_field (TYPE_FIELDS (type));
   tree empty_ctor = NULL_TREE;
 
-  ctor = reshape_init (type, ctor, tf_none);
-  if (ctor == error_mark_node)
-    return NULL;
+  /* We already called reshape_init in implicit_conversion.  */
 
   /* The conversions within the init-list aren't affected by the enclosing
      context; they're always simple copy-initialization.  */
@@ -1759,6 +1757,17 @@ implicit_conversion (tree to, tree from, tree expr, bool c_cast_p,
      to that conversion.  */
   complain &= ~tf_error;
 
+  /* Call reshape_init early to remove redundant braces.  */
+  if (expr && BRACE_ENCLOSED_INITIALIZER_P (expr)
+      && COMPLETE_TYPE_P (complete_type (to))
+      && CP_AGGREGATE_TYPE_P (to))
+    {
+      expr = reshape_init (to, expr, complain);
+      if (expr == error_mark_node)
+       return NULL;
+      from = TREE_TYPE (expr);
+    }
+
   if (TREE_CODE (to) == REFERENCE_TYPE)
     conv = reference_binding (to, from, expr, c_cast_p, flags, complain);
   else
diff --git a/gcc/testsuite/g++.dg/cpp0x/initlist96.C b/gcc/testsuite/g++.dg/cpp0x/initlist96.C
new file mode 100644 (file)
index 0000000..305565c
--- /dev/null
@@ -0,0 +1,19 @@
+// PR c++/66515
+// { dg-do compile { target c++11 } }
+
+namespace std
+{
+  template <class _E> class initializer_list
+  {
+    const _E *_M_array;
+    unsigned long _M_len;
+  };
+}
+
+struct type_t { };
+
+type_t &
+get ()
+{
+  std::initializer_list<type_t>{ { get () } };
+}
This page took 0.089963 seconds and 5 git commands to generate.