]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
decl.c (reshape_init_r): { T } is not an aggregate initializer for class T.
authorJason Merrill <jason@redhat.com>
Wed, 22 Jul 2009 03:32:39 +0000 (23:32 -0400)
committerJason Merrill <jason@gcc.gnu.org>
Wed, 22 Jul 2009 03:32:39 +0000 (23:32 -0400)
* decl.c (reshape_init_r): { T } is not an aggregate initializer
for class T.

From-SVN: r149874

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

index 86f8b50d37c4a5ac78f8f40cafee00059f5dc7f5..24ffd8b1a60962d9ed4674796f1a1d8223ebbf4b 100644 (file)
@@ -5,6 +5,9 @@
        (initialize_reference): Binding temporary to non-const && is fine.
        * decl.c (grok_reference_init): Remove error for CONSTRUCTOR.
 
+       * decl.c (reshape_init_r): { T } is not an aggregate initializer
+       for class T.
+
 2009-07-17  Richard Guenther  <rguenther@suse.de>
 
        PR c/40401
index 6fa942842acdb8326bdeaaf8c115119a8053b104..7f4509e774a14ba99a5ccc5d68c5a79567985e27 100644 (file)
@@ -4878,7 +4878,7 @@ reshape_init_class (tree type, reshape_iter *d, bool first_initializer_p)
    a CONSTRUCTOR). TYPE is the type of the variable being initialized, D is the
    iterator within the CONSTRUCTOR which points to the initializer to process.
    FIRST_INITIALIZER_P is true if this is the first initializer of the
-   CONSTRUCTOR node.  */
+   outermost CONSTRUCTOR node.  */
 
 static tree
 reshape_init_r (tree type, reshape_iter *d, bool first_initializer_p)
@@ -4923,6 +4923,10 @@ reshape_init_r (tree type, reshape_iter *d, bool first_initializer_p)
      initializer is considered for the initialization of the first
      member of the subaggregate.  */
   if (TREE_CODE (init) != CONSTRUCTOR
+      /* But don't try this for the first initializer, since that would be
+        looking through the outermost braces; A a2 = { a1 }; is not a
+        valid aggregate initialization.  */
+      && !first_initializer_p
       && can_convert_arg (type, TREE_TYPE (init), init, LOOKUP_NORMAL))
     {
       d->cur++;
index d007c46dbbdecb6eeabbf02d0fd6129cd660ab32..234c028cbaaad1095545a13720fad258892f7213 100644 (file)
@@ -1,3 +1,7 @@
+2009-07-21  Jason Merrill  <jason@redhat.com>
+
+       * g++.dg/init/aggr4.C: New.
+
 2009-07-21  Jason Merrill  <jason@redhat.com>
 
        Core issue 934
diff --git a/gcc/testsuite/g++.dg/init/aggr4.C b/gcc/testsuite/g++.dg/init/aggr4.C
new file mode 100644 (file)
index 0000000..7120e68
--- /dev/null
@@ -0,0 +1,7 @@
+struct A
+{
+  int i;
+};
+
+A a1 = { 1 };                  // ok
+A a2 = { a1 };                 // { dg-error "cannot convert" }