* [PATCH] c++: alias_ctad_tweaks and constrained dguide [PR95486]
@ 2020-07-24 13:49 Patrick Palka
2020-07-29 19:54 ` Jason Merrill
0 siblings, 1 reply; 3+ messages in thread
From: Patrick Palka @ 2020-07-24 13:49 UTC (permalink / raw)
To: gcc-patches
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. And for consistency, it changes the call to
get_constraints to go through fprime instead of f. Since the
DECL_TEMPLATE_RESULT of fprime is f, this consistency change makes
no functional difference.
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" }
--
2.28.0.rc1
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] c++: alias_ctad_tweaks and constrained dguide [PR95486]
2020-07-24 13:49 [PATCH] c++: alias_ctad_tweaks and constrained dguide [PR95486] Patrick Palka
@ 2020-07-29 19:54 ` Jason Merrill
2020-07-29 21:02 ` Patrick Palka
0 siblings, 1 reply; 3+ messages in thread
From: Jason Merrill @ 2020-07-29 19:54 UTC (permalink / raw)
To: Patrick Palka, gcc-patches
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" }
>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] c++: alias_ctad_tweaks and constrained dguide [PR95486]
2020-07-29 19:54 ` Jason Merrill
@ 2020-07-29 21:02 ` Patrick Palka
0 siblings, 0 replies; 3+ messages in thread
From: Patrick Palka @ 2020-07-29 21:02 UTC (permalink / raw)
To: Jason Merrill; +Cc: Patrick Palka, gcc-patches
On Wed, 29 Jul 2020, Jason Merrill wrote:
> 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.
That makes sense, consider that hunk gone then.
>
> > 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.
Ah yes, sorry for this thinko. I'll commit just the one hunk after a
round of testing; thanks for the review.
>
> > 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" }
> >
>
>
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2020-07-29 21:02 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-07-24 13:49 [PATCH] c++: alias_ctad_tweaks and constrained dguide [PR95486] Patrick Palka
2020-07-29 19:54 ` Jason Merrill
2020-07-29 21:02 ` Patrick Palka
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).