]> git.ipfire.org Git - thirdparty/gcc.git/commit
c++: fn parm pack expansion inside constraint [PR100138]
authorPatrick Palka <ppalka@redhat.com>
Tue, 11 May 2021 02:33:04 +0000 (22:33 -0400)
committerPatrick Palka <ppalka@redhat.com>
Tue, 11 May 2021 02:33:04 +0000 (22:33 -0400)
commite7a9f085ffd34b0d7bc4b803c182b41494f609aa
treea2acd25d921ca506cd34aaf135a903739d809b20
parentaa891c56f25baac94db004e309d1b6e40b770a95
c++: fn parm pack expansion inside constraint [PR100138]

This PR is about CTAD but the underlying problems are more general;
CTAD is a good trigger for them because of the necessary substitution
into constraints that deduction guide generation entails.

In the testcase below, when generating the implicit deduction guide for
the constrained constructor template for A, we substitute the generic
flattening map 'tsubst_args' into the constructor's constraints.  During
this substitution, tsubst_pack_expansion returns a rebuilt pack
expansion for sizeof...(xs), but doesn't carry over the
PACK_EXPANSION_LOCAL_P (and PACK_EXPANSION_SIZEOF_P) flag from the
original tree to the rebuilt one.  The flag is otherwise unset on the
original tree but gets set for the rebuilt tree from make_pack_expansion
since at_function_scope_p() is true (we're inside main).  This leads to
a crash during satisfaction when substituting into the pack expansion
because we don't have local_specializations set up (and it'd be set up
for us if PACK_EXPANSION_LOCAL_P is unset)

Similarly, tsubst_constraint needs to set cp_unevaluated so that the
substitution performed therein doesn't rely on local_specializations.
This avoids a crash during CTAD for C below.

gcc/cp/ChangeLog:

PR c++/100138
* constraint.cc (tsubst_constraint): Set up cp_unevaluated.
(satisfy_atom): Set up iloc_sentinel before calling
cxx_constant_value.
* pt.c (tsubst_pack_expansion): When returning a rebuilt pack
expansion, carry over PACK_EXPANSION_LOCAL_P and
PACK_EXPANSION_SIZEOF_P from the original pack expansion.

gcc/testsuite/ChangeLog:

PR c++/100138
* g++.dg/cpp2a/concepts-ctad4.C: New test.
gcc/cp/constraint.cc
gcc/cp/pt.c
gcc/testsuite/g++.dg/cpp2a/concepts-ctad4.C [new file with mode: 0644]