c++: optimize unifying nested templated classes [PR89231]
commit80968d5f4683ffb50dbe8051d10f754d5fd00dfb
authorPatrick Palka <ppalka@redhat.com>
Mon, 18 Sep 2023 18:54:45 +0000 (18 14:54 -0400)
committerPatrick Palka <ppalka@redhat.com>
Mon, 18 Sep 2023 18:54:45 +0000 (18 14:54 -0400)
tree288034bb500183048407366ba738ec63e84d04b1
parent6e92a6a2a72d3b7a5e1b29042d8a6a43fe1085aa
c++: optimize unifying nested templated classes [PR89231]

Since the LHS of a qualified-id is a non-deduced context, it effectively
means we can't deduce from outer template arguments of a class template
specialization.  And checking for equality between the TI_TEMPLATE of a
class specialization parm/arg already implies that the outer template
arguments are the same.  Hence recursing into outer template arguments
during unification of class specializations is redundant, so this patch
makes unify recurse only into innermost arguments.

This incidentally fixes the testcase from PR89231 because there
more_specialized_partial_inst wrongly considers the two partial
specializations to be unordered ultimately because unify for identical
parm=arg=A<Ps...>::Collect<N...> gets confused when it recurses into
parm=arg={Ps...} since Ps is outside the (innermost) level of tparms
that we're actually deducing.

PR c++/89231

gcc/cp/ChangeLog:

* pt.cc (try_class_unification): Strengthen TI_TEMPLATE equality
test by not calling most_general_template.  Only unify the
innermost levels of template arguments.
(unify) <case CLASS_TYPE>: Only unify the innermost levels of
template arguments, and only if the template is primary.

gcc/testsuite/ChangeLog:

* g++.dg/cpp0x/variadic-partial3.C: New test.
gcc/cp/pt.cc
gcc/testsuite/g++.dg/cpp0x/variadic-partial3.C [new file with mode: 0644]