* [PATCH] c++: variadic class placeholder template deduction [PR97134]
@ 2021-04-09 21:25 Patrick Palka
2021-04-12 21:27 ` Jason Merrill
0 siblings, 1 reply; 2+ messages in thread
From: Patrick Palka @ 2021-04-09 21:25 UTC (permalink / raw)
To: gcc-patches
do_class_deduction handles specially the case where we're deducing one
placeholder from another equivalent one, but here the initializer passed
to do_class_deduction is wrapped in an EXPR_PACK_EXPANSION (we're being
called from unify during get_partial_spec_bindings). This patch makes
do_class_deduction look through EXPR_PACK_EXPANSIONs so that we detect
this case as well.
Bootstrapped and regtested on x86_64-pc-linux-gnu, does this look OK for
trunk or perhaps stage1?
gcc/cp/ChangeLog:
PR c++/97134
* pt.c (do_class_deduction): Look through EXPR_PACK_EXPANSION
when checking if the initializer is an equivalent class
placeholder template parameter.
gcc/testsuite/ChangeLog:
PR c++/97134
* g++.dg/cpp2a/nontype-class43.C: New test.
---
gcc/cp/pt.c | 6 +++++-
gcc/testsuite/g++.dg/cpp2a/nontype-class43.C | 11 +++++++++++
2 files changed, 16 insertions(+), 1 deletion(-)
create mode 100644 gcc/testsuite/g++.dg/cpp2a/nontype-class43.C
diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c
index 01c807be1bb..872b08ec9ad 100644
--- a/gcc/cp/pt.c
+++ b/gcc/cp/pt.c
@@ -29265,7 +29265,11 @@ do_class_deduction (tree ptype, tree tmpl, tree init,
return ptype;
/* Initializing one placeholder from another. */
- if (init && TREE_CODE (init) == TEMPLATE_PARM_INDEX
+ if (init
+ && (TREE_CODE (init) == TEMPLATE_PARM_INDEX
+ || (TREE_CODE (init) == EXPR_PACK_EXPANSION
+ && (TREE_CODE (PACK_EXPANSION_PATTERN (init))
+ == TEMPLATE_PARM_INDEX)))
&& is_auto (TREE_TYPE (init))
&& CLASS_PLACEHOLDER_TEMPLATE (TREE_TYPE (init)) == tmpl)
return cp_build_qualified_type (TREE_TYPE (init), cp_type_quals (ptype));
diff --git a/gcc/testsuite/g++.dg/cpp2a/nontype-class43.C b/gcc/testsuite/g++.dg/cpp2a/nontype-class43.C
new file mode 100644
index 00000000000..f51684f7a62
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp2a/nontype-class43.C
@@ -0,0 +1,11 @@
+// PR c++/97134
+// { dg-do compile { target c++20 } }
+
+template<typename T>
+struct templ {};
+
+template<templ... Vs>
+struct wrapper {};
+
+template<templ... Vs> requires true
+struct wrapper<Vs...> {};
--
2.31.1.272.g89b43f80a5
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH] c++: variadic class placeholder template deduction [PR97134]
2021-04-09 21:25 [PATCH] c++: variadic class placeholder template deduction [PR97134] Patrick Palka
@ 2021-04-12 21:27 ` Jason Merrill
0 siblings, 0 replies; 2+ messages in thread
From: Jason Merrill @ 2021-04-12 21:27 UTC (permalink / raw)
To: Patrick Palka, gcc-patches
On 4/9/21 5:25 PM, Patrick Palka wrote:
> do_class_deduction handles specially the case where we're deducing one
> placeholder from another equivalent one, but here the initializer passed
> to do_class_deduction is wrapped in an EXPR_PACK_EXPANSION (we're being
> called from unify during get_partial_spec_bindings). This patch makes
> do_class_deduction look through EXPR_PACK_EXPANSIONs so that we detect
> this case as well.
>
> Bootstrapped and regtested on x86_64-pc-linux-gnu, does this look OK for
> trunk or perhaps stage1?
OK for trunk.
> gcc/cp/ChangeLog:
>
> PR c++/97134
> * pt.c (do_class_deduction): Look through EXPR_PACK_EXPANSION
> when checking if the initializer is an equivalent class
> placeholder template parameter.
>
> gcc/testsuite/ChangeLog:
>
> PR c++/97134
> * g++.dg/cpp2a/nontype-class43.C: New test.
> ---
> gcc/cp/pt.c | 6 +++++-
> gcc/testsuite/g++.dg/cpp2a/nontype-class43.C | 11 +++++++++++
> 2 files changed, 16 insertions(+), 1 deletion(-)
> create mode 100644 gcc/testsuite/g++.dg/cpp2a/nontype-class43.C
>
> diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c
> index 01c807be1bb..872b08ec9ad 100644
> --- a/gcc/cp/pt.c
> +++ b/gcc/cp/pt.c
> @@ -29265,7 +29265,11 @@ do_class_deduction (tree ptype, tree tmpl, tree init,
> return ptype;
>
> /* Initializing one placeholder from another. */
> - if (init && TREE_CODE (init) == TEMPLATE_PARM_INDEX
> + if (init
> + && (TREE_CODE (init) == TEMPLATE_PARM_INDEX
> + || (TREE_CODE (init) == EXPR_PACK_EXPANSION
> + && (TREE_CODE (PACK_EXPANSION_PATTERN (init))
> + == TEMPLATE_PARM_INDEX)))
> && is_auto (TREE_TYPE (init))
> && CLASS_PLACEHOLDER_TEMPLATE (TREE_TYPE (init)) == tmpl)
> return cp_build_qualified_type (TREE_TYPE (init), cp_type_quals (ptype));
> diff --git a/gcc/testsuite/g++.dg/cpp2a/nontype-class43.C b/gcc/testsuite/g++.dg/cpp2a/nontype-class43.C
> new file mode 100644
> index 00000000000..f51684f7a62
> --- /dev/null
> +++ b/gcc/testsuite/g++.dg/cpp2a/nontype-class43.C
> @@ -0,0 +1,11 @@
> +// PR c++/97134
> +// { dg-do compile { target c++20 } }
> +
> +template<typename T>
> +struct templ {};
> +
> +template<templ... Vs>
> +struct wrapper {};
> +
> +template<templ... Vs> requires true
> +struct wrapper<Vs...> {};
>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2021-04-12 21:28 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-04-09 21:25 [PATCH] c++: variadic class placeholder template deduction [PR97134] Patrick Palka
2021-04-12 21:27 ` 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).