aboutsummaryrefslogtreecommitdiff
path: root/gcc/cp/constexpr.cc
diff options
context:
space:
mode:
authorJason Merrill <jason@redhat.com>2022-12-06 18:10:48 -0500
committerJason Merrill <jason@redhat.com>2022-12-08 13:43:25 -0500
commitbd0485f20f4794f9787237706a6308473a8e9415 (patch)
treefce5865dde25c38a2f1d403cf3ba3154b3d0e5f1 /gcc/cp/constexpr.cc
parentd081807d8d70e3e87eae41e1560e54d503f4d465 (diff)
downloadgcc-bd0485f20f4794f9787237706a6308473a8e9415.zip
gcc-bd0485f20f4794f9787237706a6308473a8e9415.tar.gz
gcc-bd0485f20f4794f9787237706a6308473a8e9415.tar.bz2
c++: build initializer_list<string> in a loop [PR105838]
The previous patch avoided building an initializer_list<string> at all when building a vector<string>, but in situations where that isn't possible, we could still build the initializer_list with a loop over a constant array. This is represented using a VEC_INIT_EXPR, which required adjusting a couple of places that expected the initializer array to have the same type as the target array and fixing build_vec_init not to undo our efforts. PR c++/105838 gcc/cp/ChangeLog: * call.cc (convert_like_internal) [ck_list]: Use maybe_init_list_as_array. * constexpr.cc (cxx_eval_vec_init_1): Init might have a different type. * tree.cc (build_vec_init_elt): Likewise. * init.cc (build_vec_init): Handle from_array from a TARGET_EXPR. Retain TARGET_EXPR of a different type. gcc/testsuite/ChangeLog: * g++.dg/tree-ssa/initlist-opt2.C: New test.
Diffstat (limited to 'gcc/cp/constexpr.cc')
-rw-r--r--gcc/cp/constexpr.cc6
1 files changed, 3 insertions, 3 deletions
diff --git a/gcc/cp/constexpr.cc b/gcc/cp/constexpr.cc
index e43d928..3f7892a 100644
--- a/gcc/cp/constexpr.cc
+++ b/gcc/cp/constexpr.cc
@@ -5255,12 +5255,12 @@ cxx_eval_vec_init_1 (const constexpr_ctx *ctx, tree atype, tree init,
else
{
/* Copying an element. */
- gcc_assert (same_type_ignoring_top_level_qualifiers_p
- (atype, TREE_TYPE (init)));
eltinit = cp_build_array_ref (input_location, init, idx, complain);
if (!lvalue_p (init))
eltinit = move (eltinit);
- eltinit = force_rvalue (eltinit, complain);
+ eltinit = (perform_implicit_conversion_flags
+ (elttype, eltinit, complain,
+ LOOKUP_IMPLICIT|LOOKUP_NO_NARROWING));
eltinit = cxx_eval_constant_expression (&new_ctx, eltinit, lval,
non_constant_p, overflow_p);
}