On 7/24/20 9:49 AM, Patrick Palka wrote:
In the below testcase, we're ICEing from alias_ctad_tweaks ultimately
because the implied deduction guide for X's user-defined constructor
already has constraints associated with it. We then carry over these
constraints to 'fprime', the overlying deduction guide for the alias
template Y, via tsubst_decl from alias_ctad_tweaks. Later in
alias_ctad_tweaks we call get_constraints followed by set_constraints on
this overlying deduction guide without doing remove_constraints in
between, which triggers the !found assert in set_constraints.
This patch fixes this issue by adding an intervening call to
remove_constraints.
This hunk is OK.
And for consistency, it changes the call to
get_constraints to go through fprime instead of f.
This hunk is not, as what we're doing is substituting the constraints of
f to produce the constraints of f'. This change makes it less clear.
OK without that change.
Since the DECL_TEMPLATE_RESULT of fprime is f, this consistency change makes
no functional difference.
The DECL_TEMPLATE_RESULT of fprime is g, not f.
Bootstrapped and regtested on x86_64-pc-linux-gnu, does this look OK
commit?
gcc/cp/ChangeLog:
PR c++/95486
* pt.c (alias_ctad_tweaks): Obtain the associated constraints
through fprime instead of through f. Call remove_constraints
before calling set_constraints.
gcc/testsuite/ChangeLog:
PR c++/95486
* g++.dg/cpp2a/class-deduction-alias3.C: New test.
---
gcc/cp/pt.c | 7 +++++--
gcc/testsuite/g++.dg/cpp2a/class-deduction-alias3.C | 11 +++++++++++
2 files changed, 16 insertions(+), 2 deletions(-)
create mode 100644 gcc/testsuite/g++.dg/cpp2a/class-deduction-alias3.C
diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c
index b6df87a8a2e..4d955c555dc 100644
--- a/gcc/cp/pt.c
+++ b/gcc/cp/pt.c
@@ -28598,7 +28598,7 @@ alias_ctad_tweaks (tree tmpl, tree uguides)
DECL_PRIMARY_TEMPLATE (fprime) = fprime;
/* Substitute the associated constraints. */
- tree ci = get_constraints (f);
+ tree ci = get_constraints (fprime);
if (ci)
ci = tsubst_constraint_info (ci, targs, complain, in_decl);
if (ci == error_mark_node)
@@ -28616,7 +28616,10 @@ alias_ctad_tweaks (tree tmpl, tree uguides)
}
if (ci)
- set_constraints (fprime, ci);
+ {
+ remove_constraints (fprime);
+ set_constraints (fprime, ci);
+ }
}
else
{
diff --git a/gcc/testsuite/g++.dg/cpp2a/class-deduction-alias3.C
b/gcc/testsuite/g++.dg/cpp2a/class-deduction-alias3.C
new file mode 100644
index 00000000000..318d4c942ce
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp2a/class-deduction-alias3.C
@@ -0,0 +1,11 @@
+// PR c++/95486
+// { dg-do compile { target c++20 } }
+
+template<class T, class U>
+struct X { X(U) requires __is_same(U, int) {} };
+
+template<class U>
+using Y = X<void, U>;
+
+Y y{1};
+Y z{'a'}; // { dg-error "failed|no match" }