diff options
author | Jason Merrill <jason@redhat.com> | 2014-08-01 20:52:09 -0400 |
---|---|---|
committer | Jason Merrill <jason@gcc.gnu.org> | 2014-08-01 20:52:09 -0400 |
commit | 3bc63227d5eb38a70adee7375e5d3596e9c7ec01 (patch) | |
tree | 02b57039678bac4037bf83635219fe9879d8222d /gcc/cp/init.c | |
parent | f42589ed151f62e68caf4e9c8ad0cf57e6bb456f (diff) | |
download | gcc-3bc63227d5eb38a70adee7375e5d3596e9c7ec01.zip gcc-3bc63227d5eb38a70adee7375e5d3596e9c7ec01.tar.gz gcc-3bc63227d5eb38a70adee7375e5d3596e9c7ec01.tar.bz2 |
re PR c++/60417 ([DR 1518] Bogus error on C++03 aggregate initialization)
PR c++/60417
* init.c (build_vec_init): Set CONSTRUCTOR_IS_DIRECT_INIT on
init-list for trailing elements.
* typeck2.c (process_init_constructor_array): Likewise.
From-SVN: r213511
Diffstat (limited to 'gcc/cp/init.c')
-rw-r--r-- | gcc/cp/init.c | 44 |
1 files changed, 25 insertions, 19 deletions
diff --git a/gcc/cp/init.c b/gcc/cp/init.c index f8cae28..eeee5bb 100644 --- a/gcc/cp/init.c +++ b/gcc/cp/init.c @@ -3545,19 +3545,11 @@ build_vec_init (tree base, tree maxindex, tree init, try_block = begin_try_block (); } - /* If the initializer is {}, then all elements are initialized from {}. - But for non-classes, that's the same as value-initialization. */ + bool empty_list = false; if (init && BRACE_ENCLOSED_INITIALIZER_P (init) && CONSTRUCTOR_NELTS (init) == 0) - { - if (CLASS_TYPE_P (type)) - /* Leave init alone. */; - else - { - init = NULL_TREE; - explicit_value_init_p = true; - } - } + /* Skip over the handling of non-empty init lists. */ + empty_list = true; /* Maybe pull out constant value when from_array? */ @@ -3677,14 +3669,8 @@ build_vec_init (tree base, tree maxindex, tree init, vec_free (new_vec); } - /* Any elements without explicit initializers get {}. */ - if (cxx_dialect >= cxx11 && AGGREGATE_TYPE_P (type)) - init = build_constructor (init_list_type_node, NULL); - else - { - init = NULL_TREE; - explicit_value_init_p = true; - } + /* Any elements without explicit initializers get T{}. */ + empty_list = true; } else if (from_array) { @@ -3699,6 +3685,26 @@ build_vec_init (tree base, tree maxindex, tree init, } } + /* If the initializer is {}, then all elements are initialized from T{}. + But for non-classes, that's the same as value-initialization. */ + if (empty_list) + { + 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); + CONSTRUCTOR_IS_DIRECT_INIT (init) = true; + } + else + { + init = NULL_TREE; + explicit_value_init_p = true; + } + } + /* Now, default-initialize any remaining elements. We don't need to do that if a) the type does not need constructing, or b) we've already initialized all the elements. |