c++: deduction guides and ttp rewriting [PR102479]
authorPatrick Palka <ppalka@redhat.com>
Mon, 27 Sep 2021 20:01:10 +0000 (16:01 -0400)
committerPatrick Palka <ppalka@redhat.com>
Mon, 27 Sep 2021 20:01:10 +0000 (16:01 -0400)
commit51018dd1395c72b3681ae5f84eceb94320472922
tree7715eb2e871b7c6b827dd40b6c66728e489942aa
parent83668368607ac70dcce466a54673bbf88d0ab2da
c++: deduction guides and ttp rewriting [PR102479]

The problem here is ultimately that rewrite_tparm_list when rewriting a
TEMPLATE_TEMPLATE_PARM introduces a tree cycle in the rewritten
ttp that structural_comptypes can't cope with.  In particular the
DECL_TEMPLATE_PARMS of a ttp's TEMPLATE_DECL normally captures an empty
parameter list at its own level (and so the TEMPLATE_DECL doesn't appear
in its own DECL_TEMPLATE_PARMS), but rewrite_tparm_list ends up giving
it a complete parameter list.  In the new testcase below, this causes
infinite recursion from structural_comptypes when comparing Tmpl<char>
with Tmpl<long> (where both 'Tmpl's are rewritten ttps).

This patch fixes this by making rewrite_template_parm give a rewritten
template template parm an empty parameter list at its own level, thereby
avoiding the tree cycle.  Testing the alias CTAD case revealed that
we're not setting current_template_parms in alias_ctad_tweaks, which
this patch also fixes.

PR c++/102479

gcc/cp/ChangeLog:

* pt.c (rewrite_template_parm): Handle single-level tsubst_args.
Avoid a tree cycle when assigning the DECL_TEMPLATE_PARMS for a
rewritten ttp.
(alias_ctad_tweaks): Set current_template_parms accordingly.

gcc/testsuite/ChangeLog:

* g++.dg/cpp1z/class-deduction12.C: Also test alias CTAD in the
same way.
* g++.dg/cpp1z/class-deduction99.C: New test.
gcc/cp/pt.c
gcc/testsuite/g++.dg/cpp1z/class-deduction12.C
gcc/testsuite/g++.dg/cpp1z/class-deduction99.C [new file with mode: 0644]