PR c++/78345 - ICE initializing array from lambda.
authorJason Merrill <jason@redhat.com>
Fri, 17 Mar 2017 18:56:22 +0000 (14:56 -0400)
committerJason Merrill <jason@gcc.gnu.org>
Fri, 17 Mar 2017 18:56:22 +0000 (14:56 -0400)
* init.c (build_aggr_init): Check array initializer.
(build_vec_init): Check the type of a CONSTRUCTOR.

From-SVN: r246244

gcc/cp/ChangeLog
gcc/cp/init.c
gcc/testsuite/g++.dg/init/array48.C [new file with mode: 0644]
gcc/testsuite/g++.dg/torture/pr70499.C

index a5c150a71f3ab1812f77e3401ccb9c4e58392a66..7d2a56a0df818d13b625feeb01a0dd4d791fe4b2 100644 (file)
@@ -1,5 +1,9 @@
 2017-03-17  Jason Merrill  <jason@redhat.com>
 
+       PR c++/78345 - ICE initializing array from lambda.
+       * init.c (build_aggr_init): Check array initializer.
+       (build_vec_init): Check the type of a CONSTRUCTOR.
+
        PR c++/80073 - C++17 ICE with virtual base.
        * decl.c (xref_basetypes): Also check for indirect vbases.
 
index 8bfcbde903cfca1fb545e8a651b6ac24b4bb7d2a..ebb1245d9c298a1b41bc02d69cd077c9a3a2352c 100644 (file)
@@ -1617,6 +1617,10 @@ build_aggr_init (tree exp, tree init, int flags, tsubst_flags_t complain)
   if (init == error_mark_node)
     return error_mark_node;
 
+  location_t init_loc = (init
+                        ? EXPR_LOC_OR_LOC (init, input_location)
+                        : location_of (exp));
+
   TREE_READONLY (exp) = 0;
   TREE_THIS_VOLATILE (exp) = 0;
 
@@ -1656,6 +1660,16 @@ build_aggr_init (tree exp, tree init, int flags, tsubst_flags_t complain)
            TREE_TYPE (init) = cv_unqualified (itype);
          from_array = (itype && same_type_p (TREE_TYPE (init),
                                              TREE_TYPE (exp)));
+
+         if (init && !from_array
+             && !BRACE_ENCLOSED_INITIALIZER_P (init))
+           {
+             if (complain & tf_error)
+               permerror (init_loc, "array must be initialized "
+                          "with a brace-enclosed initializer");
+             else
+               return error_mark_node;
+           }
        }
 
       stmt_expr = build_vec_init (exp, NULL_TREE, init,
@@ -3945,6 +3959,9 @@ build_vec_init (tree base, tree maxindex, tree init,
          ? vec_copy_assign_is_trivial (inner_elt_type, init)
          : !TYPE_NEEDS_CONSTRUCTING (type))
       && ((TREE_CODE (init) == CONSTRUCTOR
+          && (BRACE_ENCLOSED_INITIALIZER_P (init)
+              || (same_type_ignoring_top_level_qualifiers_p
+                  (atype, TREE_TYPE (init))))
           /* Don't do this if the CONSTRUCTOR might contain something
              that might throw and require us to clean up.  */
           && (vec_safe_is_empty (CONSTRUCTOR_ELTS (init))
diff --git a/gcc/testsuite/g++.dg/init/array48.C b/gcc/testsuite/g++.dg/init/array48.C
new file mode 100644 (file)
index 0000000..27fec13
--- /dev/null
@@ -0,0 +1,7 @@
+// PR c++/78345
+// { dg-do compile { target c++11 } }
+
+struct A
+{
+  const int i;
+} a[1] = []{};                 // { dg-error "array.*init" }
index 954fea5de2f75afe3102d48560af25fafd3a1291..e08c26f56744558e033f5e0f56dc6457b42482d0 100644 (file)
@@ -1,5 +1,5 @@
 // { dg-do compile }
-// { dg-additional-options "-w -Wno-psabi" }
+// { dg-additional-options "-w -fpermissive -Wno-psabi" }
 // { dg-additional-options "-mavx" { target x86_64-*-* i?86-*-* } }
 
 typedef double __m256d __attribute__ ((__vector_size__ (32), __may_alias__));