c++: fix TTP level reduction cache
commit0bc2a1dc327af9817163cc8df78b9f9be2ad0f90
authorJason Merrill <jason@redhat.com>
Tue, 14 Mar 2023 19:16:46 +0000 (14 15:16 -0400)
committerJason Merrill <jason@redhat.com>
Wed, 3 May 2023 04:29:28 +0000 (3 00:29 -0400)
tree0c048e90fa3b8164e13610be8ec36181e2203207
parentd7cb9720ed54687bd1135c5e6ef90776a9db0bd5
c++: fix TTP level reduction cache

We try to cache the result of reduce_template_parm_level so that when we
reduce the same parm multiple times we get the same result, but this wasn't
working for template template parms because in that case TYPE is a
TEMPLATE_TEMPLATE_PARM, and so same_type_p was false because of the same
level mismatch that we're trying to adjust for.  So in that case compare the
template parms of the template template parms instead.

The result can be seen in nontype12.C, where we previously gave three
duplicate errors on line 7 and now give only one because subsequent
substitutions use the cache.

gcc/cp/ChangeLog:

* pt.cc (reduce_template_parm_level): Fix comparison of
template template parm to cached version.

gcc/testsuite/ChangeLog:

* g++.dg/template/nontype12.C: Check for duplicate error.
gcc/cp/pt.cc
gcc/testsuite/g++.dg/template/nontype12.C