https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102479
--- Comment #9 from CVS Commits <cvs-commit at gcc dot gnu.org> --- The releases/gcc-11 branch has been updated by Patrick Palka <ppa...@gcc.gnu.org>: https://gcc.gnu.org/g:f705d0f2d03cc4d9f890832798b3352553f2262f commit r11-9992-gf705d0f2d03cc4d9f890832798b3352553f2262f Author: Patrick Palka <ppa...@redhat.com> Date: Mon Sep 27 16:01:10 2021 -0400 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. (cherry picked from commit 51018dd1395c72b3681ae5f84eceb94320472922)