public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] c++: requires-expr in pack expansion using pack [PR103105]
@ 2022-04-12 16:17 Patrick Palka
  2022-04-12 16:33 ` Jason Merrill
  0 siblings, 1 reply; 4+ messages in thread
From: Patrick Palka @ 2022-04-12 16:17 UTC (permalink / raw)
  To: gcc-patches

Here after dependent substitution of {Ts...} into the alias 'wrap',
since we never partially instantiate a requires-expr, we end up with a
requires-expr whose REQUIRES_EXPR_EXTRA_ARGS contains an
ARGUMENT_PACK_SELECT (which just resolves to the parameter pack Ts).
Then when looking up the resulting dependent specialization of A, we
crash from iterative_hash_template_arg since it deliberately doesn't
handle ARGUMENT_PACK_SELECT.

Like with r12-7102-gdb5f1c17031ad8, it seems the right fix here is to
resolve ARGUMENT_PACK_SELECT arguments before storing them into an
extra args tree (such as REQUIRES_EXPR).

Bootstrapped and regtested on x86_64-pc-linux-gnu, does this look OK for
trunk/11?  For 11, we'd need to backport r12-7102 as a prereq.

	PR c++/103105
	PR c++/103706

gcc/cp/ChangeLog:

	* pt.cc (build_extra_args): Call preserve_args.

gcc/testsuite/ChangeLog:

	* g++.dg/cpp2a/concepts-requires29.C: New test.
	* g++.dg/cpp2a/concepts-requires29a.C: New test.
---
 gcc/cp/pt.cc                                  |  2 +-
 .../g++.dg/cpp2a/concepts-requires29.C        | 18 +++++++++++++++
 .../g++.dg/cpp2a/concepts-requires29a.C       | 23 +++++++++++++++++++
 3 files changed, 42 insertions(+), 1 deletion(-)
 create mode 100644 gcc/testsuite/g++.dg/cpp2a/concepts-requires29.C
 create mode 100644 gcc/testsuite/g++.dg/cpp2a/concepts-requires29a.C

diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc
index 78519562953..84712e6fc2f 100644
--- a/gcc/cp/pt.cc
+++ b/gcc/cp/pt.cc
@@ -13048,7 +13048,7 @@ build_extra_args (tree pattern, tree args, tsubst_flags_t complain)
 {
   /* Make a copy of the extra arguments so that they won't get changed
      out from under us.  */
-  tree extra = copy_template_args (args);
+  tree extra = preserve_args (copy_template_args (args), /*cow_p=*/false);
   if (local_specializations)
     if (tree locals = extract_local_specs (pattern, complain))
       extra = tree_cons (NULL_TREE, extra, locals);
diff --git a/gcc/testsuite/g++.dg/cpp2a/concepts-requires29.C b/gcc/testsuite/g++.dg/cpp2a/concepts-requires29.C
new file mode 100644
index 00000000000..5118df978c9
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp2a/concepts-requires29.C
@@ -0,0 +1,18 @@
+// PR c++/103105
+// { dg-do compile { target c++20 } }
+
+template<bool> class A;
+
+template<class... Ts>
+using wrap = A<1 != (0 + ... + requires { Ts(); })>;
+
+template<class... Ts> using type = wrap<Ts...>;
+
+using ty0 = type<>;
+using ty0 = A<true>;
+
+using ty1 = type<int>;
+using ty1 = A<false>;
+
+using ty2 = type<int, int>;
+using ty2 = A<true>;
diff --git a/gcc/testsuite/g++.dg/cpp2a/concepts-requires29a.C b/gcc/testsuite/g++.dg/cpp2a/concepts-requires29a.C
new file mode 100644
index 00000000000..c41c1e6d039
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp2a/concepts-requires29a.C
@@ -0,0 +1,23 @@
+// PR c++/103105
+// { dg-do compile { target c++20 } }
+
+template<class...> struct list;
+template<bool> struct A;
+
+template<class T, class... Ts>
+using wrap = A<1 != (0 + ... + requires { T() = Ts(); })>;
+
+template<class... Ts>
+using type = list<wrap<Ts, Ts...>...>;
+
+using ty0 = type<>;
+using ty0 = list<>;
+
+using ty1 = type<int>;
+using ty1 = list<A<true>>;
+
+using ty2 = type<int, int>;
+using ty2 = list<A<true>, A<true>>;
+
+using ty3 = type<int, int, int>;
+using ty3 = list<A<true>, A<true>, A<true>>;
-- 
2.36.0.rc0


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] c++: requires-expr in pack expansion using pack [PR103105]
  2022-04-12 16:17 [PATCH] c++: requires-expr in pack expansion using pack [PR103105] Patrick Palka
@ 2022-04-12 16:33 ` Jason Merrill
  2022-04-12 18:44   ` Patrick Palka
  0 siblings, 1 reply; 4+ messages in thread
From: Jason Merrill @ 2022-04-12 16:33 UTC (permalink / raw)
  To: Patrick Palka, gcc-patches

On 4/12/22 12:17, Patrick Palka wrote:
> Here after dependent substitution of {Ts...} into the alias 'wrap',
> since we never partially instantiate a requires-expr, we end up with a
> requires-expr whose REQUIRES_EXPR_EXTRA_ARGS contains an
> ARGUMENT_PACK_SELECT (which just resolves to the parameter pack Ts).
> Then when looking up the resulting dependent specialization of A, we
> crash from iterative_hash_template_arg since it deliberately doesn't
> handle ARGUMENT_PACK_SELECT.
> 
> Like with r12-7102-gdb5f1c17031ad8, it seems the right fix here is to
> resolve ARGUMENT_PACK_SELECT arguments before storing them into an
> extra args tree (such as REQUIRES_EXPR).
> 
> Bootstrapped and regtested on x86_64-pc-linux-gnu, does this look OK for
> trunk/11?  For 11, we'd need to backport r12-7102 as a prereq.

OK, that additional backport seems reasonable.

> 	PR c++/103105
> 	PR c++/103706
> 
> gcc/cp/ChangeLog:
> 
> 	* pt.cc (build_extra_args): Call preserve_args.
> 
> gcc/testsuite/ChangeLog:
> 
> 	* g++.dg/cpp2a/concepts-requires29.C: New test.
> 	* g++.dg/cpp2a/concepts-requires29a.C: New test.
> ---
>   gcc/cp/pt.cc                                  |  2 +-
>   .../g++.dg/cpp2a/concepts-requires29.C        | 18 +++++++++++++++
>   .../g++.dg/cpp2a/concepts-requires29a.C       | 23 +++++++++++++++++++
>   3 files changed, 42 insertions(+), 1 deletion(-)
>   create mode 100644 gcc/testsuite/g++.dg/cpp2a/concepts-requires29.C
>   create mode 100644 gcc/testsuite/g++.dg/cpp2a/concepts-requires29a.C
> 
> diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc
> index 78519562953..84712e6fc2f 100644
> --- a/gcc/cp/pt.cc
> +++ b/gcc/cp/pt.cc
> @@ -13048,7 +13048,7 @@ build_extra_args (tree pattern, tree args, tsubst_flags_t complain)
>   {
>     /* Make a copy of the extra arguments so that they won't get changed
>        out from under us.  */
> -  tree extra = copy_template_args (args);
> +  tree extra = preserve_args (copy_template_args (args), /*cow_p=*/false);
>     if (local_specializations)
>       if (tree locals = extract_local_specs (pattern, complain))
>         extra = tree_cons (NULL_TREE, extra, locals);
> diff --git a/gcc/testsuite/g++.dg/cpp2a/concepts-requires29.C b/gcc/testsuite/g++.dg/cpp2a/concepts-requires29.C
> new file mode 100644
> index 00000000000..5118df978c9
> --- /dev/null
> +++ b/gcc/testsuite/g++.dg/cpp2a/concepts-requires29.C
> @@ -0,0 +1,18 @@
> +// PR c++/103105
> +// { dg-do compile { target c++20 } }
> +
> +template<bool> class A;
> +
> +template<class... Ts>
> +using wrap = A<1 != (0 + ... + requires { Ts(); })>;
> +
> +template<class... Ts> using type = wrap<Ts...>;
> +
> +using ty0 = type<>;
> +using ty0 = A<true>;
> +
> +using ty1 = type<int>;
> +using ty1 = A<false>;
> +
> +using ty2 = type<int, int>;
> +using ty2 = A<true>;
> diff --git a/gcc/testsuite/g++.dg/cpp2a/concepts-requires29a.C b/gcc/testsuite/g++.dg/cpp2a/concepts-requires29a.C
> new file mode 100644
> index 00000000000..c41c1e6d039
> --- /dev/null
> +++ b/gcc/testsuite/g++.dg/cpp2a/concepts-requires29a.C
> @@ -0,0 +1,23 @@
> +// PR c++/103105
> +// { dg-do compile { target c++20 } }
> +
> +template<class...> struct list;
> +template<bool> struct A;
> +
> +template<class T, class... Ts>
> +using wrap = A<1 != (0 + ... + requires { T() = Ts(); })>;
> +
> +template<class... Ts>
> +using type = list<wrap<Ts, Ts...>...>;
> +
> +using ty0 = type<>;
> +using ty0 = list<>;
> +
> +using ty1 = type<int>;
> +using ty1 = list<A<true>>;
> +
> +using ty2 = type<int, int>;
> +using ty2 = list<A<true>, A<true>>;
> +
> +using ty3 = type<int, int, int>;
> +using ty3 = list<A<true>, A<true>, A<true>>;


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] c++: requires-expr in pack expansion using pack [PR103105]
  2022-04-12 16:33 ` Jason Merrill
@ 2022-04-12 18:44   ` Patrick Palka
  2022-04-12 20:14     ` Jason Merrill
  0 siblings, 1 reply; 4+ messages in thread
From: Patrick Palka @ 2022-04-12 18:44 UTC (permalink / raw)
  To: Jason Merrill; +Cc: GCC Patches

On Tue, Apr 12, 2022 at 12:33 PM Jason Merrill <jason@redhat.com> wrote:
>
> On 4/12/22 12:17, Patrick Palka wrote:
> > Here after dependent substitution of {Ts...} into the alias 'wrap',
> > since we never partially instantiate a requires-expr, we end up with a
> > requires-expr whose REQUIRES_EXPR_EXTRA_ARGS contains an
> > ARGUMENT_PACK_SELECT (which just resolves to the parameter pack Ts).
> > Then when looking up the resulting dependent specialization of A, we
> > crash from iterative_hash_template_arg since it deliberately doesn't
> > handle ARGUMENT_PACK_SELECT.
> >
> > Like with r12-7102-gdb5f1c17031ad8, it seems the right fix here is to
> > resolve ARGUMENT_PACK_SELECT arguments before storing them into an
> > extra args tree (such as REQUIRES_EXPR).
> >
> > Bootstrapped and regtested on x86_64-pc-linux-gnu, does this look OK for
> > trunk/11?  For 11, we'd need to backport r12-7102 as a prereq.
>
> OK, that additional backport seems reasonable.

Thanks a lot, committed to trunk so far.  I attempted backporting this
(along with the mentioned prereq r12-7102) but it seems we also need
to backport your r12-7857-gfc50d9a252c89c (from PR104008) before we
begin to accept the second testcase.  (Now I remember why I sat on
this PR for so long :))

>
>
> >       PR c++/103105
> >       PR c++/103706
> >
> > gcc/cp/ChangeLog:
> >
> >       * pt.cc (build_extra_args): Call preserve_args.
> >
> > gcc/testsuite/ChangeLog:
> >
> >       * g++.dg/cpp2a/concepts-requires29.C: New test.
> >       * g++.dg/cpp2a/concepts-requires29a.C: New test.
> > ---
> >   gcc/cp/pt.cc                                  |  2 +-
> >   .../g++.dg/cpp2a/concepts-requires29.C        | 18 +++++++++++++++
> >   .../g++.dg/cpp2a/concepts-requires29a.C       | 23 +++++++++++++++++++
> >   3 files changed, 42 insertions(+), 1 deletion(-)
> >   create mode 100644 gcc/testsuite/g++.dg/cpp2a/concepts-requires29.C
> >   create mode 100644 gcc/testsuite/g++.dg/cpp2a/concepts-requires29a.C
> >
> > diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc
> > index 78519562953..84712e6fc2f 100644
> > --- a/gcc/cp/pt.cc
> > +++ b/gcc/cp/pt.cc
> > @@ -13048,7 +13048,7 @@ build_extra_args (tree pattern, tree args, tsubst_flags_t complain)
> >   {
> >     /* Make a copy of the extra arguments so that they won't get changed
> >        out from under us.  */
> > -  tree extra = copy_template_args (args);
> > +  tree extra = preserve_args (copy_template_args (args), /*cow_p=*/false);
> >     if (local_specializations)
> >       if (tree locals = extract_local_specs (pattern, complain))
> >         extra = tree_cons (NULL_TREE, extra, locals);
> > diff --git a/gcc/testsuite/g++.dg/cpp2a/concepts-requires29.C b/gcc/testsuite/g++.dg/cpp2a/concepts-requires29.C
> > new file mode 100644
> > index 00000000000..5118df978c9
> > --- /dev/null
> > +++ b/gcc/testsuite/g++.dg/cpp2a/concepts-requires29.C
> > @@ -0,0 +1,18 @@
> > +// PR c++/103105
> > +// { dg-do compile { target c++20 } }
> > +
> > +template<bool> class A;
> > +
> > +template<class... Ts>
> > +using wrap = A<1 != (0 + ... + requires { Ts(); })>;
> > +
> > +template<class... Ts> using type = wrap<Ts...>;
> > +
> > +using ty0 = type<>;
> > +using ty0 = A<true>;
> > +
> > +using ty1 = type<int>;
> > +using ty1 = A<false>;
> > +
> > +using ty2 = type<int, int>;
> > +using ty2 = A<true>;
> > diff --git a/gcc/testsuite/g++.dg/cpp2a/concepts-requires29a.C b/gcc/testsuite/g++.dg/cpp2a/concepts-requires29a.C
> > new file mode 100644
> > index 00000000000..c41c1e6d039
> > --- /dev/null
> > +++ b/gcc/testsuite/g++.dg/cpp2a/concepts-requires29a.C
> > @@ -0,0 +1,23 @@
> > +// PR c++/103105
> > +// { dg-do compile { target c++20 } }
> > +
> > +template<class...> struct list;
> > +template<bool> struct A;
> > +
> > +template<class T, class... Ts>
> > +using wrap = A<1 != (0 + ... + requires { T() = Ts(); })>;
> > +
> > +template<class... Ts>
> > +using type = list<wrap<Ts, Ts...>...>;
> > +
> > +using ty0 = type<>;
> > +using ty0 = list<>;
> > +
> > +using ty1 = type<int>;
> > +using ty1 = list<A<true>>;
> > +
> > +using ty2 = type<int, int>;
> > +using ty2 = list<A<true>, A<true>>;
> > +
> > +using ty3 = type<int, int, int>;
> > +using ty3 = list<A<true>, A<true>, A<true>>;
>


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] c++: requires-expr in pack expansion using pack [PR103105]
  2022-04-12 18:44   ` Patrick Palka
@ 2022-04-12 20:14     ` Jason Merrill
  0 siblings, 0 replies; 4+ messages in thread
From: Jason Merrill @ 2022-04-12 20:14 UTC (permalink / raw)
  To: Patrick Palka; +Cc: GCC Patches

On 4/12/22 14:44, Patrick Palka wrote:
> On Tue, Apr 12, 2022 at 12:33 PM Jason Merrill <jason@redhat.com> wrote:
>>
>> On 4/12/22 12:17, Patrick Palka wrote:
>>> Here after dependent substitution of {Ts...} into the alias 'wrap',
>>> since we never partially instantiate a requires-expr, we end up with a
>>> requires-expr whose REQUIRES_EXPR_EXTRA_ARGS contains an
>>> ARGUMENT_PACK_SELECT (which just resolves to the parameter pack Ts).
>>> Then when looking up the resulting dependent specialization of A, we
>>> crash from iterative_hash_template_arg since it deliberately doesn't
>>> handle ARGUMENT_PACK_SELECT.
>>>
>>> Like with r12-7102-gdb5f1c17031ad8, it seems the right fix here is to
>>> resolve ARGUMENT_PACK_SELECT arguments before storing them into an
>>> extra args tree (such as REQUIRES_EXPR).
>>>
>>> Bootstrapped and regtested on x86_64-pc-linux-gnu, does this look OK for
>>> trunk/11?  For 11, we'd need to backport r12-7102 as a prereq.
>>
>> OK, that additional backport seems reasonable.
> 
> Thanks a lot, committed to trunk so far.  I attempted backporting this
> (along with the mentioned prereq r12-7102) but it seems we also need
> to backport your r12-7857-gfc50d9a252c89c (from PR104008) before we
> begin to accept the second testcase.  (Now I remember why I sat on
> this PR for so long :))

It's in now.

>>
>>
>>>        PR c++/103105
>>>        PR c++/103706
>>>
>>> gcc/cp/ChangeLog:
>>>
>>>        * pt.cc (build_extra_args): Call preserve_args.
>>>
>>> gcc/testsuite/ChangeLog:
>>>
>>>        * g++.dg/cpp2a/concepts-requires29.C: New test.
>>>        * g++.dg/cpp2a/concepts-requires29a.C: New test.
>>> ---
>>>    gcc/cp/pt.cc                                  |  2 +-
>>>    .../g++.dg/cpp2a/concepts-requires29.C        | 18 +++++++++++++++
>>>    .../g++.dg/cpp2a/concepts-requires29a.C       | 23 +++++++++++++++++++
>>>    3 files changed, 42 insertions(+), 1 deletion(-)
>>>    create mode 100644 gcc/testsuite/g++.dg/cpp2a/concepts-requires29.C
>>>    create mode 100644 gcc/testsuite/g++.dg/cpp2a/concepts-requires29a.C
>>>
>>> diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc
>>> index 78519562953..84712e6fc2f 100644
>>> --- a/gcc/cp/pt.cc
>>> +++ b/gcc/cp/pt.cc
>>> @@ -13048,7 +13048,7 @@ build_extra_args (tree pattern, tree args, tsubst_flags_t complain)
>>>    {
>>>      /* Make a copy of the extra arguments so that they won't get changed
>>>         out from under us.  */
>>> -  tree extra = copy_template_args (args);
>>> +  tree extra = preserve_args (copy_template_args (args), /*cow_p=*/false);
>>>      if (local_specializations)
>>>        if (tree locals = extract_local_specs (pattern, complain))
>>>          extra = tree_cons (NULL_TREE, extra, locals);
>>> diff --git a/gcc/testsuite/g++.dg/cpp2a/concepts-requires29.C b/gcc/testsuite/g++.dg/cpp2a/concepts-requires29.C
>>> new file mode 100644
>>> index 00000000000..5118df978c9
>>> --- /dev/null
>>> +++ b/gcc/testsuite/g++.dg/cpp2a/concepts-requires29.C
>>> @@ -0,0 +1,18 @@
>>> +// PR c++/103105
>>> +// { dg-do compile { target c++20 } }
>>> +
>>> +template<bool> class A;
>>> +
>>> +template<class... Ts>
>>> +using wrap = A<1 != (0 + ... + requires { Ts(); })>;
>>> +
>>> +template<class... Ts> using type = wrap<Ts...>;
>>> +
>>> +using ty0 = type<>;
>>> +using ty0 = A<true>;
>>> +
>>> +using ty1 = type<int>;
>>> +using ty1 = A<false>;
>>> +
>>> +using ty2 = type<int, int>;
>>> +using ty2 = A<true>;
>>> diff --git a/gcc/testsuite/g++.dg/cpp2a/concepts-requires29a.C b/gcc/testsuite/g++.dg/cpp2a/concepts-requires29a.C
>>> new file mode 100644
>>> index 00000000000..c41c1e6d039
>>> --- /dev/null
>>> +++ b/gcc/testsuite/g++.dg/cpp2a/concepts-requires29a.C
>>> @@ -0,0 +1,23 @@
>>> +// PR c++/103105
>>> +// { dg-do compile { target c++20 } }
>>> +
>>> +template<class...> struct list;
>>> +template<bool> struct A;
>>> +
>>> +template<class T, class... Ts>
>>> +using wrap = A<1 != (0 + ... + requires { T() = Ts(); })>;
>>> +
>>> +template<class... Ts>
>>> +using type = list<wrap<Ts, Ts...>...>;
>>> +
>>> +using ty0 = type<>;
>>> +using ty0 = list<>;
>>> +
>>> +using ty1 = type<int>;
>>> +using ty1 = list<A<true>>;
>>> +
>>> +using ty2 = type<int, int>;
>>> +using ty2 = list<A<true>, A<true>>;
>>> +
>>> +using ty3 = type<int, int, int>;
>>> +using ty3 = list<A<true>, A<true>, A<true>>;
>>
> 


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2022-04-12 20:14 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-04-12 16:17 [PATCH] c++: requires-expr in pack expansion using pack [PR103105] Patrick Palka
2022-04-12 16:33 ` Jason Merrill
2022-04-12 18:44   ` Patrick Palka
2022-04-12 20:14     ` Jason Merrill

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).