c++: constrained partial spec forward decl [PR96363]
authorPatrick Palka <ppalka@redhat.com>
Thu, 26 May 2022 13:43:14 +0000 (09:43 -0400)
committerPatrick Palka <ppalka@redhat.com>
Thu, 21 Jul 2022 14:26:13 +0000 (10:26 -0400)
commit12d8a4a0fb26729290a184c40956329bb614625f
treeed49d3271d075cad4f7437d0ce2e604ae2cde979
parent4f15d2234608e82159d030dadb17af678cfad626
c++: constrained partial spec forward decl [PR96363]

Here during cp_parser_single_declaration for #2, we were calling
associate_classtype_constraints for TPL<T> (the primary template type)
before maybe_process_partial_specialization could get a chance to
notice that we're in fact declaring a distinct constrained partial
spec and not redeclaring the primary template.  This caused us to
emit a bogus error about differing constraints b/t the primary template
and #2's constraints.  This patch fixes this by moving the call to
associate_classtype_constraints after the call to shadow_tag (which
calls maybe_process_partial_specialization) and adjusting shadow_tag to
use the return value of m_p_p_s.

Moreover, if we later try to define a constrained partial specialization
that's been declared earlier (as in the third testcase), then
maybe_new_partial_specialization correctly notices it's a redeclaration
and returns NULL_TREE.  But in this case we also need to update TYPE to
point to the redeclared partial spec (it'll otherwise continue pointing
to the primary template type, eventually leading to a bogus error).

PR c++/96363

gcc/cp/ChangeLog:

* decl.cc (shadow_tag): Use the return value of
maybe_process_partial_specialization.
* parser.cc (cp_parser_single_declaration): Call shadow_tag
before associate_classtype_constraints.
* pt.cc (maybe_new_partial_specialization): Change return type
to bool.  Take 'type' argument by mutable reference.  Set 'type'
to point to the correct constrained specialization when
appropriate.
(maybe_process_partial_specialization): Adjust accordingly.

gcc/testsuite/ChangeLog:

* g++.dg/cpp2a/concepts-partial-spec12.C: New test.
* g++.dg/cpp2a/concepts-partial-spec12a.C: New test.
* g++.dg/cpp2a/concepts-partial-spec13.C: New test.

(cherry picked from commit 97dc78d705a90c1ae83c78a7f2e24942cc3a6257)
gcc/cp/decl.cc
gcc/cp/parser.cc
gcc/cp/pt.cc
gcc/testsuite/g++.dg/cpp2a/concepts-partial-spec12.C [new file with mode: 0644]
gcc/testsuite/g++.dg/cpp2a/concepts-partial-spec12a.C [new file with mode: 0644]
gcc/testsuite/g++.dg/cpp2a/concepts-partial-spec13.C [new file with mode: 0644]