c++: bound ttp level lowering [PR109531]
commit2245459c85a3f4cde3d33bf3e4edaff08f3b2404
authorPatrick Palka <ppalka@redhat.com>
Mon, 17 Apr 2023 22:52:07 +0000 (17 18:52 -0400)
committerPatrick Palka <ppalka@redhat.com>
Mon, 17 Apr 2023 22:52:07 +0000 (17 18:52 -0400)
tree2324a6ba4b4bbeb040791f427492a333c7ed3bdb
parent60524be1e3929d83e15fceac6e2aa053c8a6fb20
c++: bound ttp level lowering [PR109531]

Here when level lowering the bound ttp TT<typename T::type> via the
substitution T=C, we're neglecting to canonicalize (and thereby strip
of simple typedefs) the substituted template arguments {A<int>} before
determining the new canonical type via hash table lookup.  This leads to
a hash mismatch ICE for the two equivalent types TT<int> and TT<A<int>>
since iterative_hash_template_arg assumes type arguments are already
canonicalized.

We can fix this by canonicalizing or coercing the substituted arguments
directly, but seeing as creation and ordinary substitution of bound ttps
both go through lookup_template_class, which in turn performs the desired
coercion/canonicalization, it seems preferable to make this code path go
through lookup_template_class as well.

PR c++/109531

gcc/cp/ChangeLog:

* pt.cc (tsubst) <case BOUND_TEMPLATE_TEMPLATE_PARM>:
In the level-lowering case just use lookup_template_class
to rebuild the bound ttp.

gcc/testsuite/ChangeLog:

* g++.dg/template/canon-type-20.C: New test.
* g++.dg/template/ttp36.C: New test.
gcc/cp/pt.cc
gcc/testsuite/g++.dg/template/canon-type-20.C [new file with mode: 0644]
gcc/testsuite/g++.dg/template/ttp36.C [new file with mode: 0644]