c++: constexpr ref to array of array [PR102307]
commit2b0c8377729a3c62a05897136666574ab939aaab
authorJason Merrill <jason@redhat.com>
Tue, 26 Apr 2022 15:15:04 +0000 (26 11:15 -0400)
committerJason Merrill <jason@redhat.com>
Tue, 17 May 2022 22:09:24 +0000 (17 18:09 -0400)
tree7e773340c84575e560cb9d78468a761c16866b08
parent2c05a2d1a8e4697ea95d65c5da601aeae327e7a7
c++: constexpr ref to array of array [PR102307]

The problem here is that first check_initializer calls
build_aggr_init_full_exprs, which does overload resolution, but then in the
case of failed constexpr throws away the result and does it again in
build_functional_cast.  But in the first overload resolution,
reshape_init_array_1 decided to reuse the inner CONSTRUCTORs because
tf_error is set, so we know we're committed.  But the second pass gets
confused by the CONSTRUCTORs with non-init-list types.

Fixed by avoiding a second pass: instead, pass the call from build_aggr_init
to build_cplus_new, which will turn it into a TARGET_EXPR.  I don't bother
to change the object argument because it will be replaced later in
simplify_aggr_init_expr.

PR c++/102307

gcc/cp/ChangeLog:

* decl.cc (check_initializer): Use build_cplus_new in case of
constexpr failure.

gcc/testsuite/ChangeLog:

* g++.dg/cpp1z/constexpr-array2.C: New test.
gcc/cp/decl.cc
gcc/testsuite/g++.dg/cpp1z/constexpr-array2.C [new file with mode: 0644]