forked from gcc-mirror/gcc
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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.
- Loading branch information
Patrick Palka
committed
May 26, 2022
1 parent
692643c
commit 97dc78d
Showing
6 changed files
with
69 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
// PR c++/96363 | ||
// { dg-do compile { target c++20 } } | ||
|
||
template<class T> class TPL; | ||
|
||
template<class T> requires true class TPL<T>; // #1 | ||
template<class T> requires false class TPL<T>; // #2 error here | ||
|
||
template<class T> requires true class TPL<T*>; // #1 | ||
template<class T> requires false class TPL<T*>; // #2 error here |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
// PR c++/96363 | ||
// { dg-do compile { target c++20 } } | ||
// A version of concepts-partial-spec12.C where the primary template is | ||
// constrained. | ||
|
||
template<class T> concept C = true; | ||
|
||
template<C T> class TPL; | ||
|
||
template<C T> requires true class TPL<T>; // #1 | ||
template<C T> requires false class TPL<T>; // #2 error here | ||
|
||
template<C T> requires true class TPL<T*>; // #1 | ||
template<C T> requires false class TPL<T*>; // #2 error here |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// PR c++/99501 | ||
// { dg-do compile { target c++20 } } | ||
|
||
template<auto> struct X; | ||
|
||
template<auto V> requires requires{V.a;} struct X<V>; | ||
template<auto V> requires requires{V.b;} struct X<V>; | ||
|
||
template<auto V> requires requires{V.a;} struct X<V> { static const bool v = false; }; | ||
template<auto V> requires requires{V.b;} struct X<V> { static const bool v = true; }; | ||
|
||
struct A { int a; }; | ||
static_assert(!X<A{}>::v); | ||
|
||
struct B { int b; }; | ||
static_assert(X<B{}>::v); |