The initializer-list paper did not allow brace elision for all
list-initialization, only for the traditional C aggregate
initialization. But extending it to all list-initialization has been
deemed desirable, so this patch implements that.
Tested x86_64-pc-linux-gnu, applying to trunk.
commit 649364f67c5020e231818384cd03bc6ec17c9ca5
Author: Jason Merrill <ja...@redhat.com>
Date: Wed Feb 1 06:15:19 2012 -0500
Core 1270
* call.c (build_aggr_conv): Call reshape_init.
(convert_like_real): Likewise.
* typeck2.c (process_init_constructor): Clear TREE_CONSTANT if
not all constant.
diff --git a/gcc/cp/call.c b/gcc/cp/call.c
index c962ca0..8baad82 100644
--- a/gcc/cp/call.c
+++ b/gcc/cp/call.c
@@ -886,6 +886,10 @@ build_aggr_conv (tree type, tree ctor, int flags)
tree field = next_initializable_field (TYPE_FIELDS (type));
tree empty_ctor = NULL_TREE;
+ ctor = reshape_init (type, ctor, tf_none);
+ if (ctor == error_mark_node)
+ return NULL;
+
for (; field; field = next_initializable_field (DECL_CHAIN (field)))
{
tree ftype = TREE_TYPE (field);
@@ -5795,6 +5799,7 @@ convert_like_real (conversion *convs, tree expr, tree fn, int argnum,
expr = build2 (COMPLEX_EXPR, totype, real, imag);
return fold_if_not_in_template (expr);
}
+ expr = reshape_init (totype, expr, complain);
return get_target_expr (digest_init (totype, expr, complain));
default:
diff --git a/gcc/cp/typeck2.c b/gcc/cp/typeck2.c
index a2606f1..974f92f 100644
--- a/gcc/cp/typeck2.c
+++ b/gcc/cp/typeck2.c
@@ -1392,7 +1392,10 @@ process_init_constructor (tree type, tree init, tsubst_flags_t complain)
TREE_TYPE (init) = type;
if (TREE_CODE (type) == ARRAY_TYPE && TYPE_DOMAIN (type) == NULL_TREE)
cp_complete_array_type (&TREE_TYPE (init), init, /*do_default=*/0);
- if (!(flags & PICFLAG_NOT_ALL_CONSTANT))
+ if (flags & PICFLAG_NOT_ALL_CONSTANT)
+ /* Make sure TREE_CONSTANT isn't set from build_constructor. */
+ TREE_CONSTANT (init) = false;
+ else
{
TREE_CONSTANT (init) = 1;
if (!(flags & PICFLAG_NOT_ALL_SIMPLE))
diff --git a/gcc/testsuite/g++.dg/cpp0x/initlist65.C b/gcc/testsuite/g++.dg/cpp0x/initlist65.C
new file mode 100644
index 0000000..3612706
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/initlist65.C
@@ -0,0 +1,9 @@
+// Core 1270
+// { dg-options -std=c++11 }
+
+struct A
+{
+ int i[2];
+};
+
+A f() { return {1,2}; }