]> git.ipfire.org Git - thirdparty/gcc.git/commit
c++: fix crash with pack indexing in noexcept [PR121325]
authorMarek Polacek <polacek@redhat.com>
Mon, 24 Nov 2025 22:31:22 +0000 (17:31 -0500)
committerMarek Polacek <polacek@redhat.com>
Wed, 26 Nov 2025 19:20:19 +0000 (14:20 -0500)
commit856fae983bca6a934b74f47c7cd21e6919035fc0
treed4c8c9a7dc1ea5351b01fe7b3f8c6b71335a771b
parente97550a7d0e1a8b31a76b0877c0e90a0163da7ee
c++: fix crash with pack indexing in noexcept [PR121325]

In my r15-6792 patch I added a call to tsubst in tsubst_pack_index
to fully instantiate args#N in the pack.

Here we are in an unevaluated context, but since the pack is
a TREE_VEC, we call tsubst_template_args which has cp_evaluated
at the beginning.  That causes a crash because we trip on the
assert in tsubst_expr/PARM_DECL:

  gcc_assert (cp_unevaluated_operand);

because retrieve_local_specialization didn't find anything (becase
there are no local_specializations yet).

We can avoid the cp_evaluated by calling the new tsubst_tree_vec,
which creates a new TREE_VEC and substitutes each element.

PR c++/121325

gcc/cp/ChangeLog:

* pt.cc (tsubst_tree_vec): New.
(tsubst_pack_index): Call it.

gcc/testsuite/ChangeLog:

* g++.dg/cpp26/pack-indexing18.C: New test.

Reviewed-by: Patrick Palka <ppalka@redhat.com>
gcc/cp/pt.cc
gcc/testsuite/g++.dg/cpp26/pack-indexing18.C [new file with mode: 0644]