[Bug c++/125539] [14/15/16/17 Regression] ICE on define_aggregate in comma expression since r14-4796
cvs-commit at gcc dot gnu.org
gcc-bugzilla@gcc.gnu.org
Tue Jun 16 15:09:27 GMT 2026
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=125539
--- Comment #4 from GCC Commits <cvs-commit at gcc dot gnu.org> ---
The trunk branch has been updated by Marek Polacek <mpolacek@gcc.gnu.org>:
https://gcc.gnu.org/g:9af58600fd08d986894051be4d0f37454ad38abe
commit r17-1592-g9af58600fd08d986894051be4d0f37454ad38abe
Author: Marek Polacek <polacek@redhat.com>
Date: Mon Jun 1 17:32:38 2026 -0400
c++: ICE in tsubst_expr with comma expr [PR125539]
Here we crash because a TARGET_EXPR gets into tsubst_expr with something
like:
template<typename>
constexpr static A a = (A{}, A{});
Pre r14-4796, when we had tsubst_copy, we didn't crash because we had
an early exit when substituting with args=NULL_TREE. tsubst_expr
deliberately doesn't have that early exit.
Note that
template<typename>
constexpr static A a = A{};
works because expand_aggr_init_1 sees a COMPOUND_LITERAL_P and does the
early exit without calling expand_default_init. But with a COMPOUND_EXPR
we don't take that path.
The TARGET_EXPR is created via check_initializer ->
build_aggr_init_full_exprs
-> build_aggr_init -> expand_aggr_init_1 -> expand_default_init ->
ocp_convert
-> build_cplus_new -> build_target_expr. I tried adjusting the big
and ugly check in check_initializer before build_aggr_init_full_exprs
but that didn't work out. I also tried avoiding the call to ocp_convert
but that broke some reflection tests.
We can fix this by calling perform_implicit_conversion in a template to
create an IMPLICIT_CONV_EXPR, then build_cplus_new won't create a
TARGET_EXPR.
PR c++/125539
gcc/cp/ChangeLog:
* cvt.cc (ocp_convert): In a template, always call
perform_implicit_conversion. Pass flags to
perform_implicit_conversion_flags.
* decl.cc (check_initializer): Remove a call to
build_implicit_conv_flags.
gcc/testsuite/ChangeLog:
* g++.dg/cpp1y/var-templ89.C: New test.
Reviewed-by: Jason Merrill <jason@redhat.com>
More information about the Gcc-bugs
mailing list