c++: constrained nested partial specialization [PR92103]
authorPatrick Palka <ppalka@redhat.com>
Wed, 3 Jun 2020 20:40:28 +0000 (16:40 -0400)
committerPatrick Palka <ppalka@redhat.com>
Wed, 3 Jun 2020 20:40:28 +0000 (16:40 -0400)
commitaee69073cdb8086d393f12474c6177e75467ceaa
tree4492342ea2044fcc67e5ea4c1ff117d09be93475
parent3fb68f2e666d9de7e0326af9f43b12c9e98f19a6
c++: constrained nested partial specialization [PR92103]

When determining the most specialized partial specialization of a
primary template that is nested inside a class template, we first
tsubst the outer template arguments into the TEMPLATE_DECL of each
partial specialization, and then check for satisfaction of each of the
new TEMPLATE_DECL's constraints.

But tsubst_template_decl does not currently guarantee that constraints
from the original DECL_TEMPLATE_RESULT get reattached to the new
DECL_TEMPLATE_RESULT.  In the testcase below, this leads to the
constraints_satisfied_p check in most_specialized_partial_spec to
trivially return true for each of the partial specializations.

I'm not sure if such a guarantee would be desirable, but in this case we
can just check constraints_satisfied_p on the original TEMPLATE_DECL
instead of on the tsubsted TEMPLATE_DECL here, which is what this patch
does (alongside some reorganizing).

gcc/cp/ChangeLog:

PR c++/92103
* pt.c (most_specialized_partial_spec): Reorganize the loop over
DECL_TEMPLATE_SPECIALIZATIONS.  Check constraints_satisfied_p on
the original template declaration, not on the tsubsted one.

gcc/testsuite/ChangeLog:

PR c++/92103
* g++.dg/cpp2a/concepts-partial-spec7.C: New test.
gcc/cp/pt.c
gcc/testsuite/g++.dg/cpp2a/concepts-partial-spec7.C [new file with mode: 0644]