re PR c++/49216 ([C++0x] ICE on compiling new-expression with braced-init-list for...
authorJason Merrill <jason@redhat.com>
Tue, 21 Jun 2011 02:24:17 +0000 (22:24 -0400)
committerJason Merrill <jason@gcc.gnu.org>
Tue, 21 Jun 2011 02:24:17 +0000 (22:24 -0400)
PR c++/49216
* init.c (build_vec_init): Don't try to use a CONSTRUCTOR when
base is a pointer.
* typeck2.c (process_init_constructor_array): Use {} for classes,
too.
* call.c (convert_like_real): Handle substitution failure.

From-SVN: r175237

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

index 6b84111ae1a844bf161a7be4aaeea15a03edb7c6..a48f9c5a6b7160112f3d7a475f404788e5b1c10d 100644 (file)
@@ -1,5 +1,12 @@
 2011-06-20  Jason Merrill  <jason@redhat.com>
 
+       PR c++/49216
+       * init.c (build_vec_init): Don't try to use a CONSTRUCTOR when
+       base is a pointer.
+       * typeck2.c (process_init_constructor_array): Use {} for classes,
+       too.
+       * call.c (convert_like_real): Handle substitution failure.
+
        PR c++/48138
        * pt.c (canonicalize_type_argument): New.
        (convert_template_argument, unify): Use it.
index e9d6e7ea354c6928d63aa0b1d7f5df7a104df1d0..caf95b077ce4b8d7883644c73244d7bfe07b215f 100644 (file)
@@ -5621,7 +5621,7 @@ convert_like_real (conversion *convs, tree expr, tree fn, int argnum,
            expr = build_cplus_new (totype, expr, complain);
 
            /* Remember that this was list-initialization.  */
-           if (convs->check_narrowing)
+           if (convs->check_narrowing && expr != error_mark_node)
              TARGET_EXPR_LIST_INIT_P (expr) = true;
          }
 
index 140e064b6599b9645d8a66b3642acd967038591e..3c347a4521f983a2c84914731bf5f0185c9a1754 100644 (file)
@@ -3082,8 +3082,9 @@ build_vec_init (tree base, tree maxindex, tree init,
       unsigned HOST_WIDE_INT idx;
       tree field, elt;
       /* Should we try to create a constant initializer?  */
-      bool try_const = (literal_type_p (inner_elt_type)
-                       || TYPE_HAS_CONSTEXPR_CTOR (inner_elt_type));
+      bool try_const = (TREE_CODE (atype) == ARRAY_TYPE
+                       && (literal_type_p (inner_elt_type)
+                           || TYPE_HAS_CONSTEXPR_CTOR (inner_elt_type)));
       bool saw_non_const = false;
       bool saw_const = false;
       /* If we're initializing a static array, we want to do static
index 6d6267e8d728fa370fe505afc2a5cb41e5f99f0e..ff2949c510d2fed81206f84e199720905ba56a5b 100644 (file)
@@ -1051,14 +1051,9 @@ process_init_constructor_array (tree type, tree init,
        if (type_build_ctor_call (TREE_TYPE (type)))
          {
            /* If this type needs constructors run for default-initialization,
-             we can't rely on the back end to do it for us, so build up
-             TARGET_EXPRs.  If the type in question is a class, just build
-             one up; if it's an array, recurse.  */
-           if (MAYBE_CLASS_TYPE_P (TREE_TYPE (type)))
-              next = build_functional_cast (TREE_TYPE (type), NULL_TREE,
-                                            complain);
-           else
-             next = build_constructor (init_list_type_node, NULL);
+             we can't rely on the back end to do it for us, so make the
+             initialization explicit by list-initializing from {}.  */
+           next = build_constructor (init_list_type_node, NULL);
            next = digest_init (TREE_TYPE (type), next, complain);
          }
        else if (!zero_init_p (TREE_TYPE (type)))
index f18487f74b46d8eac7fd1262ccf8fe18364f64ff..3da23b1bf84b004ff2172c70103952b8c81d88cf 100644 (file)
@@ -1,3 +1,8 @@
+2011-06-20  Jason Merrill  <jason@redhat.com>
+
+       PR c++/49216
+       * g++.dg/cpp0x/initlist53.C: New.
+
 2011-06-20  Tobias Burnus  <burnus@net-b.de>
 
        PR fortran/18918
diff --git a/gcc/testsuite/g++.dg/cpp0x/initlist53.C b/gcc/testsuite/g++.dg/cpp0x/initlist53.C
new file mode 100644 (file)
index 0000000..750ebba
--- /dev/null
@@ -0,0 +1,20 @@
+// PR c++/49216
+// { dg-options -std=c++0x }
+// { dg-do run }
+
+#include <initializer_list>
+extern "C" void abort();
+
+bool constructed;
+
+struct A
+{
+  A(std::initializer_list<int>) { constructed = true; }
+};
+
+int main() {
+  new A[1]{};
+  int *p = new int[1]{};
+  if (p[0] != 0 || !constructed)
+    abort();
+}