public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] [PR86747] tsubst friend tpl ctxt before looking it up for dupes
@ 2018-11-16 22:33 Alexandre Oliva
  2018-12-06  1:17 ` Jason Merrill
  0 siblings, 1 reply; 2+ messages in thread
From: Alexandre Oliva @ 2018-11-16 22:33 UTC (permalink / raw)
  To: gcc-patches; +Cc: jason, nathan

When a member template is redeclared as a friend, we enter the context
of the member before looking it up, and then we check that the decls
are compatible.  However, when the member template references template
types of the enclosing context, say an enclosing template class, the
compare fails because the friend decl is already tsubsted, whereas the
looked up name isn't.

The problem is that the enclosing context is taken from the friend
declaration before tsubsting it, so we look up in the context of the
generic template instead of that of the tsubsted one we're
specializing.  The solution is to tsubst the enclosing context when
it's a non-namespace scope.

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


for  gcc/cp/ChangeLog

	PR c++/86747
	* pt.c (tsubst_friend_class): Enter tsubsted class context.

for  gcc/testsuite/ChangeLog

	PR c++/86747
	* g++.dg/pr86747.C: New.
---
 gcc/cp/pt.c                    |    5 ++++-
 gcc/testsuite/g++.dg/pr86747.C |    8 ++++++++
 2 files changed, 12 insertions(+), 1 deletion(-)
 create mode 100644 gcc/testsuite/g++.dg/pr86747.C

diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c
index 83d0a74b209f..82c8019431b8 100644
--- a/gcc/cp/pt.c
+++ b/gcc/cp/pt.c
@@ -10568,7 +10568,10 @@ tsubst_friend_class (tree friend_tmpl, tree args)
   if (TREE_CODE (context) == NAMESPACE_DECL)
     push_nested_namespace (context);
   else
-    push_nested_class (context);
+    {
+      context = tsubst (context, args, tf_error, NULL_TREE);
+      push_nested_class (context);
+    }
 
   tmpl = lookup_name_real (DECL_NAME (friend_tmpl), /*prefer_type=*/false,
 			   /*non_class=*/false, /*block_p=*/false,
diff --git a/gcc/testsuite/g++.dg/pr86747.C b/gcc/testsuite/g++.dg/pr86747.C
new file mode 100644
index 000000000000..5b0a0bb95146
--- /dev/null
+++ b/gcc/testsuite/g++.dg/pr86747.C
@@ -0,0 +1,8 @@
+// { dg-do compile }
+
+template <typename T> class A {
+  template <void (A::*p)()> class C; // #1
+  template <void (A::*q)()> friend class C; // #2
+};
+
+A<double> a;

-- 
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] 2+ messages in thread

* Re: [PATCH] [PR86747] tsubst friend tpl ctxt before looking it up for dupes
  2018-11-16 22:33 [PATCH] [PR86747] tsubst friend tpl ctxt before looking it up for dupes Alexandre Oliva
@ 2018-12-06  1:17 ` Jason Merrill
  0 siblings, 0 replies; 2+ messages in thread
From: Jason Merrill @ 2018-12-06  1:17 UTC (permalink / raw)
  To: Alexandre Oliva, gcc-patches; +Cc: nathan

On 11/16/18 5:32 PM, Alexandre Oliva wrote:
> When a member template is redeclared as a friend, we enter the context
> of the member before looking it up, and then we check that the decls
> are compatible.  However, when the member template references template
> types of the enclosing context, say an enclosing template class, the
> compare fails because the friend decl is already tsubsted, whereas the
> looked up name isn't.
> 
> The problem is that the enclosing context is taken from the friend
> declaration before tsubsting it, so we look up in the context of the
> generic template instead of that of the tsubsted one we're
> specializing.  The solution is to tsubst the enclosing context when
> it's a non-namespace scope.
> 
> Regstrapped on i686- and x86_64-linux-gnu.  Ok to install?

OK.

> 
> 
> for  gcc/cp/ChangeLog
> 
> 	PR c++/86747
> 	* pt.c (tsubst_friend_class): Enter tsubsted class context.
> 
> for  gcc/testsuite/ChangeLog
> 
> 	PR c++/86747
> 	* g++.dg/pr86747.C: New.
> ---
>   gcc/cp/pt.c                    |    5 ++++-
>   gcc/testsuite/g++.dg/pr86747.C |    8 ++++++++
>   2 files changed, 12 insertions(+), 1 deletion(-)
>   create mode 100644 gcc/testsuite/g++.dg/pr86747.C
> 
> diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c
> index 83d0a74b209f..82c8019431b8 100644
> --- a/gcc/cp/pt.c
> +++ b/gcc/cp/pt.c
> @@ -10568,7 +10568,10 @@ tsubst_friend_class (tree friend_tmpl, tree args)
>     if (TREE_CODE (context) == NAMESPACE_DECL)
>       push_nested_namespace (context);
>     else
> -    push_nested_class (context);
> +    {
> +      context = tsubst (context, args, tf_error, NULL_TREE);
> +      push_nested_class (context);
> +    }
>   
>     tmpl = lookup_name_real (DECL_NAME (friend_tmpl), /*prefer_type=*/false,
>   			   /*non_class=*/false, /*block_p=*/false,
> diff --git a/gcc/testsuite/g++.dg/pr86747.C b/gcc/testsuite/g++.dg/pr86747.C
> new file mode 100644
> index 000000000000..5b0a0bb95146
> --- /dev/null
> +++ b/gcc/testsuite/g++.dg/pr86747.C
> @@ -0,0 +1,8 @@
> +// { dg-do compile }
> +
> +template <typename T> class A {
> +  template <void (A::*p)()> class C; // #1
> +  template <void (A::*q)()> friend class C; // #2
> +};
> +
> +A<double> a;
> 

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

end of thread, other threads:[~2018-12-06  1:17 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-11-16 22:33 [PATCH] [PR86747] tsubst friend tpl ctxt before looking it up for dupes Alexandre Oliva
2018-12-06  1:17 ` 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).