public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] [PR87012] canonicalize ref type for tmpl arg
@ 2018-11-16 22:33 Alexandre Oliva
  2018-12-06  1:25 ` Jason Merrill
  0 siblings, 1 reply; 5+ messages in thread
From: Alexandre Oliva @ 2018-11-16 22:33 UTC (permalink / raw)
  To: gcc-patches; +Cc: jason, nathan

When binding an object to a template parameter of reference type, we
take the address of the object and dereference that address.  The type
of the address may still carry (template) typedefs, but
verify_unstripped_args_1 rejects such typedefs other than in the top
level of template arguments.

We might special-case INDIRECT_REFs, but I suppose we're better off
canonicalizing the desired type for the address before converting to
it.

Regstrapped on i686- and x86_64-linux-gnu.  Ok to install?


for  gcc/cp/ChangeLog

	PR c++/87012
	* pt.c (canonicalize_type_argument): Declare earlier.
	(convert_nontype_argument): Call it on addr expr.

for  gcc/testsuite/ChangeLog

	PR c++/87012
	* g++.dg/cpp0x/pr87012.C: New.
---
 gcc/cp/pt.c                          |    4 ++++
 gcc/testsuite/g++.dg/cpp0x/pr87012.C |   11 +++++++++++
 2 files changed, 15 insertions(+)
 create mode 100644 gcc/testsuite/g++.dg/cpp0x/pr87012.C

diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c
index b58ec06a09e5..83d0a74b209f 100644
--- a/gcc/cp/pt.c
+++ b/gcc/cp/pt.c
@@ -227,6 +227,8 @@ static tree make_argument_pack (tree);
 static void register_parameter_specializations (tree, tree);
 static tree enclosing_instantiation_of (tree tctx);
 
+static tree canonicalize_type_argument (tree arg, tsubst_flags_t complain);
+
 /* Make the current scope suitable for access checking when we are
    processing T.  T can be FUNCTION_DECL for instantiated function
    template, VAR_DECL for static member variable, or TYPE_DECL for
@@ -7016,6 +7018,8 @@ convert_nontype_argument (tree type, tree expr, tsubst_flags_t complain)
 	    return NULL_TREE;
 	}
 
+      type = canonicalize_type_argument (type, complain);
+
       if (!same_type_p (type, TREE_TYPE (expr)))
 	expr = build_nop (type, expr);
     }
diff --git a/gcc/testsuite/g++.dg/cpp0x/pr87012.C b/gcc/testsuite/g++.dg/cpp0x/pr87012.C
new file mode 100644
index 000000000000..fd3eea47c390
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/pr87012.C
@@ -0,0 +1,11 @@
+// { dg-do compile { target c++11 } }
+
+template<class T>
+using ref = T&;
+
+int x;
+
+template<template<class> class T, T<int>>
+struct X { };
+
+struct Y : X<ref, x> { };

-- 
Alexandre Oliva, freedom fighter   https://FSFLA.org/blogs/lxo
Be the change, be Free!         FSF Latin America board member
GNU Toolchain Engineer                Free Software Evangelist
Hay que enGNUrecerse, pero sin perder la terGNUra jamás-GNUChe

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

* Re: [PATCH] [PR87012] canonicalize ref type for tmpl arg
  2018-11-16 22:33 [PATCH] [PR87012] canonicalize ref type for tmpl arg Alexandre Oliva
@ 2018-12-06  1:25 ` Jason Merrill
  2018-12-14  2:34   ` Alexandre Oliva
  0 siblings, 1 reply; 5+ messages in thread
From: Jason Merrill @ 2018-12-06  1:25 UTC (permalink / raw)
  To: Alexandre Oliva, gcc-patches; +Cc: nathan

On 11/16/18 5:32 PM, Alexandre Oliva wrote:
> When binding an object to a template parameter of reference type, we
> take the address of the object and dereference that address.  The type
> of the address may still carry (template) typedefs, but
> verify_unstripped_args_1 rejects such typedefs other than in the top
> level of template arguments.
> 
> We might special-case INDIRECT_REFs, but I suppose we're better off
> canonicalizing the desired type for the address before converting to
> it.
> 
> Regstrapped on i686- and x86_64-linux-gnu.  Ok to install?
> 
> 
> for  gcc/cp/ChangeLog
> 
> 	PR c++/87012
> 	* pt.c (canonicalize_type_argument): Declare earlier.
> 	(convert_nontype_argument): Call it on addr expr.
> 
> for  gcc/testsuite/ChangeLog
> 
> 	PR c++/87012
> 	* g++.dg/cpp0x/pr87012.C: New.
> ---
>   gcc/cp/pt.c                          |    4 ++++
>   gcc/testsuite/g++.dg/cpp0x/pr87012.C |   11 +++++++++++
>   2 files changed, 15 insertions(+)
>   create mode 100644 gcc/testsuite/g++.dg/cpp0x/pr87012.C
> 
> diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c
> index b58ec06a09e5..83d0a74b209f 100644
> --- a/gcc/cp/pt.c
> +++ b/gcc/cp/pt.c
> @@ -227,6 +227,8 @@ static tree make_argument_pack (tree);
>   static void register_parameter_specializations (tree, tree);
>   static tree enclosing_instantiation_of (tree tctx);
>   
> +static tree canonicalize_type_argument (tree arg, tsubst_flags_t complain);
> +
>   /* Make the current scope suitable for access checking when we are
>      processing T.  T can be FUNCTION_DECL for instantiated function
>      template, VAR_DECL for static member variable, or TYPE_DECL for
> @@ -7016,6 +7018,8 @@ convert_nontype_argument (tree type, tree expr, tsubst_flags_t complain)
>   	    return NULL_TREE;
>   	}
>   
> +      type = canonicalize_type_argument (type, complain);

I would expect that this same issue would come up with other types; I 
think we want to fix this sooner, when we are figuring out what type we 
want to convert the argument to.

Jason

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

* Re: [PATCH] [PR87012] canonicalize ref type for tmpl arg
  2018-12-06  1:25 ` Jason Merrill
@ 2018-12-14  2:34   ` Alexandre Oliva
  2018-12-14 14:31     ` Jason Merrill
  0 siblings, 1 reply; 5+ messages in thread
From: Alexandre Oliva @ 2018-12-14  2:34 UTC (permalink / raw)
  To: Jason Merrill; +Cc: gcc-patches, nathan

On Dec  5, 2018, Jason Merrill <jason@redhat.com> wrote:

> I would expect that this same issue would come up with other types; I
> think we want to fix this sooner, when we are figuring out what type
> we want to convert the argument to.

You mean like this?

[PR87012] canonicalize ref type for tmpl arg

When binding an object to a template parameter of reference type, we
take the address of the object and dereference that address.  The type
of the address may still carry (template) typedefs, but
verify_unstripped_args_1 rejects such typedefs other than in the top
level of template arguments.

Canonicalizing the type we want to convert to right after any
substitutions or deductions avoids that issue.

Regstrapped on x86_64- and i686-linux-gnu.  Ok to install?


for  gcc/cp/ChangeLog

	PR c++/87012
	* pt.c (convert_template_argument): Canonicalize type after
	tsubst/deduce.

for  gcc/testsuite/ChangeLog

	PR c++/87012
	* g++.dg/cpp0x/pr87012.C: New.
---
 gcc/cp/pt.c                          |    2 ++
 gcc/testsuite/g++.dg/cpp0x/pr87012.C |   11 +++++++++++
 2 files changed, 13 insertions(+)
 create mode 100644 gcc/testsuite/g++.dg/cpp0x/pr87012.C

diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c
index 72ae7173d92c..0d388c67459a 100644
--- a/gcc/cp/pt.c
+++ b/gcc/cp/pt.c
@@ -8018,6 +8018,8 @@ convert_template_argument (tree parm,
       if (invalid_nontype_parm_type_p (t, complain))
 	return error_mark_node;
 
+      t = canonicalize_type_argument (t, complain);
+
       if (!type_dependent_expression_p (orig_arg)
 	  && !uses_template_parms (t))
 	/* We used to call digest_init here.  However, digest_init
diff --git a/gcc/testsuite/g++.dg/cpp0x/pr87012.C b/gcc/testsuite/g++.dg/cpp0x/pr87012.C
new file mode 100644
index 000000000000..fd3eea47c390
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/pr87012.C
@@ -0,0 +1,11 @@
+// { dg-do compile { target c++11 } }
+
+template<class T>
+using ref = T&;
+
+int x;
+
+template<template<class> class T, T<int>>
+struct X { };
+
+struct Y : X<ref, x> { };



-- 
Alexandre Oliva, freedom fighter   https://FSFLA.org/blogs/lxo
Be the change, be Free!         FSF Latin America board member
GNU Toolchain Engineer                Free Software Evangelist
Hay que enGNUrecerse, pero sin perder la terGNUra jamás-GNUChe

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

* Re: [PATCH] [PR87012] canonicalize ref type for tmpl arg
  2018-12-14  2:34   ` Alexandre Oliva
@ 2018-12-14 14:31     ` Jason Merrill
  2018-12-19  8:03       ` Alexandre Oliva
  0 siblings, 1 reply; 5+ messages in thread
From: Jason Merrill @ 2018-12-14 14:31 UTC (permalink / raw)
  To: Alexandre Oliva; +Cc: gcc-patches List, Nathan Sidwell

On Thu, Dec 13, 2018 at 8:37 PM Alexandre Oliva <aoliva@redhat.com> wrote:
> On Dec  5, 2018, Jason Merrill <jason@redhat.com> wrote:
>
> > I would expect that this same issue would come up with other types; I
> > think we want to fix this sooner, when we are figuring out what type
> > we want to convert the argument to.
>
> You mean like this?
>
> [PR87012] canonicalize ref type for tmpl arg
>
> When binding an object to a template parameter of reference type, we
> take the address of the object and dereference that address.  The type
> of the address may still carry (template) typedefs, but
> verify_unstripped_args_1 rejects such typedefs other than in the top
> level of template arguments.
>
> Canonicalizing the type we want to convert to right after any
> substitutions or deductions avoids that issue.
>
> Regstrapped on x86_64- and i686-linux-gnu.  Ok to install?
>
>
> for  gcc/cp/ChangeLog
>
>         PR c++/87012
>         * pt.c (convert_template_argument): Canonicalize type after
>         tsubst/deduce.
>
> for  gcc/testsuite/ChangeLog
>
>         PR c++/87012
>         * g++.dg/cpp0x/pr87012.C: New.
> ---
>  gcc/cp/pt.c                          |    2 ++
>  gcc/testsuite/g++.dg/cpp0x/pr87012.C |   11 +++++++++++
>  2 files changed, 13 insertions(+)
>  create mode 100644 gcc/testsuite/g++.dg/cpp0x/pr87012.C
>
> diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c
> index 72ae7173d92c..0d388c67459a 100644
> --- a/gcc/cp/pt.c
> +++ b/gcc/cp/pt.c
> @@ -8018,6 +8018,8 @@ convert_template_argument (tree parm,
>        if (invalid_nontype_parm_type_p (t, complain))
>         return error_mark_node;
>
> +      t = canonicalize_type_argument (t, complain);

Yes, like that, thanks.  It might be a bit of an optimization to skip
this when t == TREE_TYPE (parm).  OK either way.

Jason

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

* Re: [PATCH] [PR87012] canonicalize ref type for tmpl arg
  2018-12-14 14:31     ` Jason Merrill
@ 2018-12-19  8:03       ` Alexandre Oliva
  0 siblings, 0 replies; 5+ messages in thread
From: Alexandre Oliva @ 2018-12-19  8:03 UTC (permalink / raw)
  To: Jason Merrill; +Cc: gcc-patches List, Nathan Sidwell

On Dec 14, 2018, Jason Merrill <jason@redhat.com> wrote:

> Yes, like that, thanks.  It might be a bit of an optimization to skip
> this when t == TREE_TYPE (parm).  OK either way.

Thanks, I've put the suggested optimization in.

Here's what I'm about to install.


[PR87012] canonicalize ref type for tmpl arg

When binding an object to a template parameter of reference type, we
take the address of the object and dereference that address.  The type
of the address may still carry (template) typedefs, but
verify_unstripped_args_1 rejects such typedefs other than in the top
level of template arguments.

Canonicalizing the type we want to convert to right after any
substitutions or deductions avoids that issue.


for  gcc/cp/ChangeLog

	PR c++/87012
	* pt.c (convert_template_argument): Canonicalize type after
	tsubst/deduce.

for  gcc/testsuite/ChangeLog

	PR c++/87012
	* g++.dg/cpp0x/pr87012.C: New.
---
 gcc/cp/pt.c                          |    3 +++
 gcc/testsuite/g++.dg/cpp0x/pr87012.C |   11 +++++++++++
 2 files changed, 14 insertions(+)
 create mode 100644 gcc/testsuite/g++.dg/cpp0x/pr87012.C

diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c
index 79eef12112fb..e99de71ea9e2 100644
--- a/gcc/cp/pt.c
+++ b/gcc/cp/pt.c
@@ -8019,6 +8019,9 @@ convert_template_argument (tree parm,
       if (invalid_nontype_parm_type_p (t, complain))
 	return error_mark_node;
 
+      if (t != TREE_TYPE (parm))
+	t = canonicalize_type_argument (t, complain);
+
       if (!type_dependent_expression_p (orig_arg)
 	  && !uses_template_parms (t))
 	/* We used to call digest_init here.  However, digest_init
diff --git a/gcc/testsuite/g++.dg/cpp0x/pr87012.C b/gcc/testsuite/g++.dg/cpp0x/pr87012.C
new file mode 100644
index 000000000000..fd3eea47c390
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/pr87012.C
@@ -0,0 +1,11 @@
+// { dg-do compile { target c++11 } }
+
+template<class T>
+using ref = T&;
+
+int x;
+
+template<template<class> class T, T<int>>
+struct X { };
+
+struct Y : X<ref, x> { };


-- 
Alexandre Oliva, freedom fighter   https://FSFLA.org/blogs/lxo
Be the change, be Free!         FSF Latin America board member
GNU Toolchain Engineer                Free Software Evangelist
Hay que enGNUrecerse, pero sin perder la terGNUra jamás-GNUChe

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

end of thread, other threads:[~2018-12-19  8:03 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-11-16 22:33 [PATCH] [PR87012] canonicalize ref type for tmpl arg Alexandre Oliva
2018-12-06  1:25 ` Jason Merrill
2018-12-14  2:34   ` Alexandre Oliva
2018-12-14 14:31     ` Jason Merrill
2018-12-19  8:03       ` Alexandre Oliva

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