re PR c++/65154 (ICE with {} initialized array with string)
authorMikhail Maltsev <maltsevm@gmail.com>
Thu, 26 Mar 2015 19:51:58 +0000 (19:51 +0000)
committerJason Merrill <jason@gcc.gnu.org>
Thu, 26 Mar 2015 19:51:58 +0000 (15:51 -0400)
PR c++/65154
* init.c (build_vec_init): Fix initializing aggregates
with empty init list.

From-SVN: r221704

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

index e3699f63c046216619ecc5c5a8936af0153117b0..684129b2200cf05abea199dcc8ccd36f04bd869d 100644 (file)
@@ -1,3 +1,9 @@
+2015-03-26  Mikhail Maltsev  <maltsevm@gmail.com>
+
+       PR c++/65154
+       * init.c (build_vec_init): Fix initializing aggregates
+       with empty init list.
+
 2015-03-26  Jason Merrill  <jason@redhat.com>
 
        PR c++/65525
index 0274663c8f47813c0096165dbdb458bd916a6b9e..957a7a4e6e8823096536bb974e95c2208b971a6f 100644 (file)
@@ -3716,11 +3716,7 @@ build_vec_init (tree base, tree maxindex, tree init,
        {
          if (cxx_dialect >= cxx11 && AGGREGATE_TYPE_P (type))
            {
-             if (BRACE_ENCLOSED_INITIALIZER_P (init)
-                 && CONSTRUCTOR_NELTS (init) == 0)
-               /* Reuse it.  */;
-             else
-               init = build_constructor (init_list_type_node, NULL);
+             init = build_constructor (init_list_type_node, NULL);
              CONSTRUCTOR_IS_DIRECT_INIT (init) = true;
            }
          else
diff --git a/gcc/testsuite/g++.dg/init/array39.C b/gcc/testsuite/g++.dg/init/array39.C
new file mode 100644 (file)
index 0000000..2fd8937
--- /dev/null
@@ -0,0 +1,46 @@
+// PR c++/65154
+// { dg-do run { target c++11 } }
+
+int cnt1 = 0,
+    cnt2 = 0;
+
+struct S_empty
+{
+    S_empty () {
+       cnt1++;
+    };
+};
+
+struct C1
+{
+  S_empty s;
+};
+
+struct S_init
+{
+  S_init () : i(42)
+  {
+    cnt2++;
+  };
+  int i;
+};
+
+struct C2
+{
+  S_init a, b;
+};
+
+int
+main ()
+{
+  C1 c1[5]{};
+  C2 c2[1]{};
+
+  if (c2[0].a.i != 42 || c2[0].b.i != 42)
+    return 1;
+
+  if (cnt1 != 5 || cnt2 != 2)
+    return 1;
+
+  return 0;
+}