public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] c++: deducing empty type vs non-type argument pack
@ 2023-07-18 15:18 Patrick Palka
  2023-07-18 16:26 ` Jason Merrill
  0 siblings, 1 reply; 2+ messages in thread
From: Patrick Palka @ 2023-07-18 15:18 UTC (permalink / raw)
  To: gcc-patches; +Cc: jason, Patrick Palka

Bootstrapped and regtested on x86_64-pc-linux-gnu, does this look OK for
trunk?  Also verified by way of gcc_assert that we never see
TEMPLATE_PARM_INDEX here.

-- >8 --

Within a template parameter list, a non-type template parameter pack is
represented as a PARM_DECL.  But in a couple of spots where we need to
deduce an empty argument pack, we test for TEMPLATE_PARM_INDEX (within a
template parameter list) instead of for PARM_DECL, which means we end up
using TYPE_ARGUMENT_PACK even in the non-type case.  This patch fixes
this (seemingly harmless) bug.

gcc/cp/ChangeLog:

	* pt.cc (type_unification_real): Test for PARM_DECL instead
	of TEMPLATE_PARM_INDEX to distinguish a type vs non-type
	template parameter pack.
	(type_targs_deducible_from): Likewise.
---
 gcc/cp/pt.cc | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc
index 3987ffc509a..d342ab5929a 100644
--- a/gcc/cp/pt.cc
+++ b/gcc/cp/pt.cc
@@ -23345,7 +23345,7 @@ type_unification_real (tree tparms,
 	    {
 	      tree arg;
 
-	      if (TREE_CODE (tparm) == TEMPLATE_PARM_INDEX)
+	      if (TREE_CODE (tparm) == PARM_DECL)
 		{
 		  arg = make_node (NONTYPE_ARGUMENT_PACK);
 		  TREE_CONSTANT (arg) = 1;
@@ -30369,7 +30369,7 @@ type_targs_deducible_from (tree tmpl, tree type)
 	if (template_parameter_pack_p (tparm))
 	  {
 	    tree arg;
-	    if (TREE_CODE (tparm) == TEMPLATE_PARM_INDEX)
+	    if (TREE_CODE (tparm) == PARM_DECL)
 	      {
 		arg = make_node (NONTYPE_ARGUMENT_PACK);
 		TREE_CONSTANT (arg) = 1;
-- 
2.41.0.363.g5e238546dc


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

* Re: [PATCH] c++: deducing empty type vs non-type argument pack
  2023-07-18 15:18 [PATCH] c++: deducing empty type vs non-type argument pack Patrick Palka
@ 2023-07-18 16:26 ` Jason Merrill
  0 siblings, 0 replies; 2+ messages in thread
From: Jason Merrill @ 2023-07-18 16:26 UTC (permalink / raw)
  To: Patrick Palka, gcc-patches

On 7/18/23 11:18, Patrick Palka wrote:
> Bootstrapped and regtested on x86_64-pc-linux-gnu, does this look OK for
> trunk?  Also verified by way of gcc_assert that we never see
> TEMPLATE_PARM_INDEX here.

OK.

> -- >8 --
> 
> Within a template parameter list, a non-type template parameter pack is
> represented as a PARM_DECL.  But in a couple of spots where we need to
> deduce an empty argument pack, we test for TEMPLATE_PARM_INDEX (within a
> template parameter list) instead of for PARM_DECL, which means we end up
> using TYPE_ARGUMENT_PACK even in the non-type case.  This patch fixes
> this (seemingly harmless) bug.
> 
> gcc/cp/ChangeLog:
> 
> 	* pt.cc (type_unification_real): Test for PARM_DECL instead
> 	of TEMPLATE_PARM_INDEX to distinguish a type vs non-type
> 	template parameter pack.
> 	(type_targs_deducible_from): Likewise.
> ---
>   gcc/cp/pt.cc | 4 ++--
>   1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc
> index 3987ffc509a..d342ab5929a 100644
> --- a/gcc/cp/pt.cc
> +++ b/gcc/cp/pt.cc
> @@ -23345,7 +23345,7 @@ type_unification_real (tree tparms,
>   	    {
>   	      tree arg;
>   
> -	      if (TREE_CODE (tparm) == TEMPLATE_PARM_INDEX)
> +	      if (TREE_CODE (tparm) == PARM_DECL)
>   		{
>   		  arg = make_node (NONTYPE_ARGUMENT_PACK);
>   		  TREE_CONSTANT (arg) = 1;
> @@ -30369,7 +30369,7 @@ type_targs_deducible_from (tree tmpl, tree type)
>   	if (template_parameter_pack_p (tparm))
>   	  {
>   	    tree arg;
> -	    if (TREE_CODE (tparm) == TEMPLATE_PARM_INDEX)
> +	    if (TREE_CODE (tparm) == PARM_DECL)
>   	      {
>   		arg = make_node (NONTYPE_ARGUMENT_PACK);
>   		TREE_CONSTANT (arg) = 1;


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

end of thread, other threads:[~2023-07-18 16:26 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-07-18 15:18 [PATCH] c++: deducing empty type vs non-type argument pack Patrick Palka
2023-07-18 16:26 ` 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).