From 5ba2ce8208e4a70665c5f0d87c7bc788e6e79bac Mon Sep 17 00:00:00 2001 From: jason Date: Wed, 22 Jul 2009 03:32:39 +0000 Subject: [PATCH] * decl.c (reshape_init_r): { T } is not an aggregate initializer for class T. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@149874 138bc75d-0d04-0410-961f-82ee72b054a4 --- gcc/cp/ChangeLog | 3 +++ gcc/cp/decl.c | 6 +++++- gcc/testsuite/ChangeLog | 4 ++++ gcc/testsuite/g++.dg/init/aggr4.C | 7 +++++++ 4 files changed, 19 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/g++.dg/init/aggr4.C diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 86f8b50..24ffd8b 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -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 PR c/40401 diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c index 6fa9428..7f4509e 100644 --- a/gcc/cp/decl.c +++ b/gcc/cp/decl.c @@ -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++; diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index d007c46..234c028 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,5 +1,9 @@ 2009-07-21 Jason Merrill + * g++.dg/init/aggr4.C: New. + +2009-07-21 Jason Merrill + Core issue 934 * g++.dg/cpp0x/initlist22.C: New. diff --git a/gcc/testsuite/g++.dg/init/aggr4.C b/gcc/testsuite/g++.dg/init/aggr4.C new file mode 100644 index 0000000..7120e68 --- /dev/null +++ b/gcc/testsuite/g++.dg/init/aggr4.C @@ -0,0 +1,7 @@ +struct A +{ + int i; +}; + +A a1 = { 1 }; // ok +A a2 = { a1 }; // { dg-error "cannot convert" } -- 2.7.4