re PR c++/65815 (brace elision doesn't work in NSDMI)
authorPaolo Carlini <paolo.carlini@oracle.com>
Tue, 9 Jun 2015 14:59:08 +0000 (14:59 +0000)
committerPaolo Carlini <paolo@gcc.gnu.org>
Tue, 9 Jun 2015 14:59:08 +0000 (14:59 +0000)
/cp
2015-06-09  Paolo Carlini  <paolo.carlini@oracle.com>

PR c++/65815
* typeck2.c (digest_nsdmi_init): On aggregates use reshape_init.
* init.c (expand_default_init): Likewise.

/testsuite
2015-06-09  Paolo Carlini  <paolo.carlini@oracle.com>

PR c++/65815
* g++.dg/cpp0x/nsdmi-aggr1.C: New.
* g++.dg/cpp0x/mem-init-aggr1.C: Likewise.

From-SVN: r224286

gcc/cp/ChangeLog
gcc/cp/init.c
gcc/cp/typeck2.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/cpp0x/mem-init-aggr1.C [new file with mode: 0644]
gcc/testsuite/g++.dg/cpp0x/nsdmi-aggr1.C [new file with mode: 0644]

index b71893c2fc6d3d00cc5813e9ad69e958f42c57b8..bf48e969712b26d4bb285c16c17931b8ffe7bfb1 100644 (file)
@@ -1,3 +1,9 @@
+2015-06-09  Paolo Carlini  <paolo.carlini@oracle.com>
+
+       PR c++/65815
+       * typeck2.c (digest_nsdmi_init): On aggregates use reshape_init.
+       * init.c (expand_default_init): Likewise.
+
 2015-06-09  Jason Merrill  <jason@redhat.com>
 
        PR c++/66383
index aad3b4409a7f7478ec9a6420e6b03344b7be5f13..ef4f0ff65d37b6ad084be73f17400ef1526ac0ca 100644 (file)
@@ -1614,7 +1614,10 @@ expand_default_init (tree binfo, tree true_exp, tree exp, tree init, int flags,
       && CP_AGGREGATE_TYPE_P (type))
     /* A brace-enclosed initializer for an aggregate.  In C++0x this can
        happen for direct-initialization, too.  */
-    init = digest_init (type, init, complain);
+    {
+      init = reshape_init (type, init, complain);
+      init = digest_init (type, init, complain);
+    }
 
   /* A CONSTRUCTOR of the target's type is a previously digested
      initializer, whether that happened just above or in
index 22a55801601c5dd6334b751b5bf485b4bc8c160a..b077f0273d165f4a09bf9f8c0d94dd41a61dc3a4 100644 (file)
@@ -1158,10 +1158,14 @@ digest_nsdmi_init (tree decl, tree init)
 {
   gcc_assert (TREE_CODE (decl) == FIELD_DECL);
 
+  tree type = TREE_TYPE (decl);
   int flags = LOOKUP_IMPLICIT;
   if (DIRECT_LIST_INIT_P (init))
     flags = LOOKUP_NORMAL;
-  init = digest_init_flags (TREE_TYPE (decl), init, flags);
+  if (BRACE_ENCLOSED_INITIALIZER_P (init)
+      && CP_AGGREGATE_TYPE_P (type))
+    init = reshape_init (type, init, tf_warning_or_error);
+  init = digest_init_flags (type, init, flags);
   if (TREE_CODE (init) == TARGET_EXPR)
     /* This represents the whole initialization.  */
     TARGET_EXPR_DIRECT_INIT_P (init) = true;
index 737dfad8d8cc2f382b77fa21d1926849e2698867..1443d33478c82521a7b8e968e13c6a1964847eea 100644 (file)
@@ -1,3 +1,9 @@
+2015-06-09  Paolo Carlini  <paolo.carlini@oracle.com>
+
+       PR c++/65815
+       * g++.dg/cpp0x/nsdmi-aggr1.C: New.
+       * g++.dg/cpp0x/mem-init-aggr1.C: Likewise.
+
 2015-06-09  Marek Polacek  <polacek@redhat.com>
 
        PR tree-optimization/66299
diff --git a/gcc/testsuite/g++.dg/cpp0x/mem-init-aggr1.C b/gcc/testsuite/g++.dg/cpp0x/mem-init-aggr1.C
new file mode 100644 (file)
index 0000000..51a2ede
--- /dev/null
@@ -0,0 +1,10 @@
+// PR c++/65815
+// { dg-do compile { target c++11 } }
+
+struct array {
+  int data [2];
+};
+
+struct X : array {
+  X() : array{ 1, 2 } { }
+};
diff --git a/gcc/testsuite/g++.dg/cpp0x/nsdmi-aggr1.C b/gcc/testsuite/g++.dg/cpp0x/nsdmi-aggr1.C
new file mode 100644 (file)
index 0000000..e07d392
--- /dev/null
@@ -0,0 +1,10 @@
+// PR c++/65815
+// { dg-do compile { target c++11 } }
+
+struct array {
+  int data [2];
+};
+
+struct X {
+  array a = { 1, 2 };
+};