public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [pushed] c++: using from enclosing class template [PR105006]
@ 2022-03-23 12:56 Jason Merrill
  2022-03-23 14:29 ` Patrick Palka
  0 siblings, 1 reply; 3+ messages in thread
From: Jason Merrill @ 2022-03-23 12:56 UTC (permalink / raw)
  To: gcc-patches

Here, DECL_DEPENDENT_P was false for the second using because Row<eT> is
"the current instantiation", so lookup succeeds.  But since Row itself has a
dependent using-decl for operator(), the set of functions imported by the
second using is dependent, so we should set the flag.

Tested x86_64-pc-linux-gnu, applying to trunk.

	PR c++/105006

gcc/cp/ChangeLog:

	* name-lookup.cc (lookup_using_decl): Set DECL_DEPENDENT_P if lookup
	finds a dependent using.

gcc/testsuite/ChangeLog:

	* g++.dg/template/using30.C: New test.
---
 gcc/cp/name-lookup.cc                   | 15 +++++++++++++++
 gcc/testsuite/g++.dg/template/using30.C | 13 +++++++++++++
 2 files changed, 28 insertions(+)
 create mode 100644 gcc/testsuite/g++.dg/template/using30.C

diff --git a/gcc/cp/name-lookup.cc b/gcc/cp/name-lookup.cc
index 323f96bcd24..ea947fabb7e 100644
--- a/gcc/cp/name-lookup.cc
+++ b/gcc/cp/name-lookup.cc
@@ -5665,6 +5665,21 @@ lookup_using_decl (tree scope, name_lookup &lookup)
 	lookup.value = lookup_member (binfo, lookup.name, /*protect=*/2,
 				      /*want_type=*/false, tf_none);
 
+      /* If the lookup in the base contains a dependent using, this
+	 using is also dependent.  */
+      if (!dependent_p && lookup.value)
+	{
+	  tree val = lookup.value;
+	  if (tree fns = maybe_get_fns (val))
+	    val = fns;
+	  for (tree f: lkp_range (val))
+	    if (TREE_CODE (f) == USING_DECL && DECL_DEPENDENT_P (f))
+	      {
+		dependent_p = true;
+		break;
+	      }
+	}
+
       if (!depscope && b_kind < bk_proper_base)
 	{
 	  if (cxx_dialect >= cxx20 && lookup.value
diff --git a/gcc/testsuite/g++.dg/template/using30.C b/gcc/testsuite/g++.dg/template/using30.C
new file mode 100644
index 00000000000..914252dd14c
--- /dev/null
+++ b/gcc/testsuite/g++.dg/template/using30.C
@@ -0,0 +1,13 @@
+// PR c++/105006
+
+template<class eT>
+class Row {
+  using eT::operator();
+  void operator()();
+  class fixed;
+};
+
+template<class eT>
+class Row<eT>::fixed : Row {
+  using Row::operator();
+};

base-commit: 4a9e92164a547afcf8cd3fc593c7660238ad2d59
-- 
2.27.0


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

* Re: [pushed] c++: using from enclosing class template [PR105006]
  2022-03-23 12:56 [pushed] c++: using from enclosing class template [PR105006] Jason Merrill
@ 2022-03-23 14:29 ` Patrick Palka
  2022-03-23 17:17   ` Jason Merrill
  0 siblings, 1 reply; 3+ messages in thread
From: Patrick Palka @ 2022-03-23 14:29 UTC (permalink / raw)
  To: Jason Merrill; +Cc: gcc-patches

On Wed, 23 Mar 2022, Jason Merrill via Gcc-patches wrote:

> Here, DECL_DEPENDENT_P was false for the second using because Row<eT> is
> "the current instantiation", so lookup succeeds.  But since Row itself has a
> dependent using-decl for operator(), the set of functions imported by the
> second using is dependent, so we should set the flag.
> 
> Tested x86_64-pc-linux-gnu, applying to trunk.
> 
> 	PR c++/105006
> 
> gcc/cp/ChangeLog:
> 
> 	* name-lookup.cc (lookup_using_decl): Set DECL_DEPENDENT_P if lookup
> 	finds a dependent using.
> 
> gcc/testsuite/ChangeLog:
> 
> 	* g++.dg/template/using30.C: New test.
> ---
>  gcc/cp/name-lookup.cc                   | 15 +++++++++++++++
>  gcc/testsuite/g++.dg/template/using30.C | 13 +++++++++++++
>  2 files changed, 28 insertions(+)
>  create mode 100644 gcc/testsuite/g++.dg/template/using30.C
> 
> diff --git a/gcc/cp/name-lookup.cc b/gcc/cp/name-lookup.cc
> index 323f96bcd24..ea947fabb7e 100644
> --- a/gcc/cp/name-lookup.cc
> +++ b/gcc/cp/name-lookup.cc
> @@ -5665,6 +5665,21 @@ lookup_using_decl (tree scope, name_lookup &lookup)
>  	lookup.value = lookup_member (binfo, lookup.name, /*protect=*/2,
>  				      /*want_type=*/false, tf_none);
>  
> +      /* If the lookup in the base contains a dependent using, this
> +	 using is also dependent.  */
> +      if (!dependent_p && lookup.value)

I wonder if it'd be worthwhile to also test dependent_type_p (scope) here
here to avoid iterating over the lookup set when it can't possibly contain
a dependent using-decl.

> +	{
> +	  tree val = lookup.value;
> +	  if (tree fns = maybe_get_fns (val))
> +	    val = fns;
> +	  for (tree f: lkp_range (val))
> +	    if (TREE_CODE (f) == USING_DECL && DECL_DEPENDENT_P (f))
> +	      {
> +		dependent_p = true;
> +		break;
> +	      }
> +	}
> +
>        if (!depscope && b_kind < bk_proper_base)
>  	{
>  	  if (cxx_dialect >= cxx20 && lookup.value
> diff --git a/gcc/testsuite/g++.dg/template/using30.C b/gcc/testsuite/g++.dg/template/using30.C
> new file mode 100644
> index 00000000000..914252dd14c
> --- /dev/null
> +++ b/gcc/testsuite/g++.dg/template/using30.C
> @@ -0,0 +1,13 @@
> +// PR c++/105006
> +
> +template<class eT>
> +class Row {
> +  using eT::operator();
> +  void operator()();
> +  class fixed;
> +};
> +
> +template<class eT>
> +class Row<eT>::fixed : Row {
> +  using Row::operator();
> +};
> 
> base-commit: 4a9e92164a547afcf8cd3fc593c7660238ad2d59
> -- 
> 2.27.0
> 
> 


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

* Re: [pushed] c++: using from enclosing class template [PR105006]
  2022-03-23 14:29 ` Patrick Palka
@ 2022-03-23 17:17   ` Jason Merrill
  0 siblings, 0 replies; 3+ messages in thread
From: Jason Merrill @ 2022-03-23 17:17 UTC (permalink / raw)
  To: Patrick Palka; +Cc: gcc-patches

[-- Attachment #1: Type: text/plain, Size: 234 bytes --]

On 3/23/22 10:29, Patrick Palka wrote:
> I wonder if it'd be worthwhile to also test dependent_type_p (scope) here
> here to avoid iterating over the lookup set when it can't possibly contain
> a dependent using-decl.

Good thought:


[-- Attachment #2: 0001-c-tweak-PR105006-fix.patch --]
[-- Type: text/x-patch, Size: 1104 bytes --]

From b1005f60c17d693e9fbc38a9481b3cd896d26785 Mon Sep 17 00:00:00 2001
From: Jason Merrill <jason@redhat.com>
Date: Wed, 23 Mar 2022 12:22:20 -0400
Subject: [PATCH] c++: tweak PR105006 fix
To: gcc-patches@gcc.gnu.org

Checking dependent_type_p avoids needing to walk the overloads in cases
where it would not be possible to find a dependent using.

	PR c++/105006

gcc/cp/ChangeLog:

	* name-lookup.cc (lookup_using_decl): Check that scope is
	a dependent type before looking for dependent using.
---
 gcc/cp/name-lookup.cc | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/gcc/cp/name-lookup.cc b/gcc/cp/name-lookup.cc
index ea947fabb7e..3c7b626350f 100644
--- a/gcc/cp/name-lookup.cc
+++ b/gcc/cp/name-lookup.cc
@@ -5667,7 +5667,7 @@ lookup_using_decl (tree scope, name_lookup &lookup)
 
       /* If the lookup in the base contains a dependent using, this
 	 using is also dependent.  */
-      if (!dependent_p && lookup.value)
+      if (!dependent_p && lookup.value && dependent_type_p (scope))
 	{
 	  tree val = lookup.value;
 	  if (tree fns = maybe_get_fns (val))
-- 
2.27.0


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

end of thread, other threads:[~2022-03-23 17:17 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-03-23 12:56 [pushed] c++: using from enclosing class template [PR105006] Jason Merrill
2022-03-23 14:29 ` Patrick Palka
2022-03-23 17: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).