We were failing to set TARGET_EXPR_LIST_INIT_P on a TARGET_EXPR created
from aggregate initialization, which is needed to avoid calling the copy
constructor when using that TARGET_EXPR to initialize the element of the
underlying array of the initializer_list.
We also should avoid building a CONSTRUCTOR with an error_mark_node
inside it.
Tested x86_64-pc-linux-gnu, applying to trunk and 4.8.
commit a4cdb0d20f4f81b8c265ff5d10f676d09c48edd1
Author: Jason Merrill <ja...@redhat.com>
Date: Fri Jan 31 09:39:13 2014 -0500
PR c++/59646
* call.c (convert_like_real) [ck_aggr]: Set TARGET_EXPR_LIST_INIT_P.
[ck_list]: Check for error_mark_node.
(build_aggr_conv): Set LOOKUP_NO_NARROWING and check_narrowing.
diff --git a/gcc/cp/call.c b/gcc/cp/call.c
index 71f95db..d4e8a28 100644
--- a/gcc/cp/call.c
+++ b/gcc/cp/call.c
@@ -886,6 +886,8 @@ build_aggr_conv (tree type, tree ctor, int flags, tsubst_flags_t complain)
if (ctor == error_mark_node)
return NULL;
+ flags |= LOOKUP_NO_NARROWING;
+
for (; field; field = next_initializable_field (DECL_CHAIN (field)))
{
tree ftype = TREE_TYPE (field);
@@ -926,6 +928,7 @@ build_aggr_conv (tree type, tree ctor, int flags, tsubst_flags_t complain)
c->type = type;
c->rank = cr_exact;
c->user_conv_p = true;
+ c->check_narrowing = true;
c->u.next = NULL;
return c;
}
@@ -6111,6 +6114,8 @@ convert_like_real (conversion *convs, tree expr, tree fn, int argnum,
to avoid the error about taking the address of a temporary. */
array = cp_build_addr_expr (array, complain);
array = cp_convert (build_pointer_type (elttype), array, complain);
+ if (array == error_mark_node)
+ return error_mark_node;
/* Build up the initializer_list object. */
totype = complete_type (totype);
@@ -6135,8 +6140,11 @@ convert_like_real (conversion *convs, tree expr, tree fn, int argnum,
return fold_if_not_in_template (expr);
}
expr = reshape_init (totype, expr, complain);
- return get_target_expr_sfinae (digest_init (totype, expr, complain),
+ expr = get_target_expr_sfinae (digest_init (totype, expr, complain),
complain);
+ if (expr != error_mark_node)
+ TARGET_EXPR_LIST_INIT_P (expr) = true;
+ return expr;
default:
break;
diff --git a/gcc/testsuite/g++.dg/cpp0x/initlist79.C b/gcc/testsuite/g++.dg/cpp0x/initlist79.C
new file mode 100644
index 0000000..5a1914d
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/initlist79.C
@@ -0,0 +1,8 @@
+// PR c++/59646
+// { dg-require-effective-target c++11 }
+
+#include <initializer_list>
+
+struct A {};
+
+std::initializer_list<volatile A> x = {{}};