aboutsummaryrefslogtreecommitdiff
path: root/gcc/cp
diff options
context:
space:
mode:
authorJason Merrill <jason@redhat.com>2023-06-08 16:21:38 -0400
committerJason Merrill <jason@redhat.com>2023-06-09 11:41:42 -0400
commit35d2c40e4ac9ba57ae82e4722e557a2028d0cf13 (patch)
treefda0d9ac73242a3daf2c8a57162f86a717a366bc /gcc/cp
parent0f8f1dee851c23bce19977b2531cf69b4da9f88f (diff)
downloadgcc-35d2c40e4ac9ba57ae82e4722e557a2028d0cf13.zip
gcc-35d2c40e4ac9ba57ae82e4722e557a2028d0cf13.tar.gz
gcc-35d2c40e4ac9ba57ae82e4722e557a2028d0cf13.tar.bz2
c++: init-list of uncopyable type [PR110102]
The maybe_init_list_as_range optimization is a form of copy elision, but we can only elide well-formed copies. PR c++/110102 gcc/cp/ChangeLog: * call.cc (maybe_init_list_as_array): Check that the element type is copyable. gcc/testsuite/ChangeLog: * g++.dg/cpp0x/initlist-opt1.C: New test.
Diffstat (limited to 'gcc/cp')
-rw-r--r--gcc/cp/call.cc8
1 files changed, 8 insertions, 0 deletions
diff --git a/gcc/cp/call.cc b/gcc/cp/call.cc
index d6154f1..354773f 100644
--- a/gcc/cp/call.cc
+++ b/gcc/cp/call.cc
@@ -4272,6 +4272,14 @@ maybe_init_list_as_array (tree elttype, tree init)
if (has_non_trivial_temporaries (first))
return NULL_TREE;
+ /* We can't do this if copying from the initializer_list would be
+ ill-formed. */
+ tree copy_argtypes = make_tree_vec (1);
+ TREE_VEC_ELT (copy_argtypes, 0)
+ = cp_build_qualified_type (elttype, TYPE_QUAL_CONST);
+ if (!is_xible (INIT_EXPR, elttype, copy_argtypes))
+ return NULL_TREE;
+
init_elttype = cp_build_qualified_type (init_elttype, TYPE_QUAL_CONST);
tree arr = build_array_of_n_type (init_elttype, CONSTRUCTOR_NELTS (init));
arr = finish_compound_literal (arr, init, tf_none);