[pushed] c++: using from enclosing class template [PR105006]

Message ID 20220323125604.3296543-1-jason@redhat.com
State Committed
Commit a3f78748fab6b24e3d4a8b319afd3f8afa17248f
Headers
Series [pushed] c++: using from enclosing class template [PR105006] |

Commit Message

Jason Merrill March 23, 2022, 12:56 p.m. UTC
  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


base-commit: 4a9e92164a547afcf8cd3fc593c7660238ad2d59
  

Comments

Patrick Palka March 23, 2022, 2:29 p.m. UTC | #1
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
> 
>
  
Jason Merrill March 23, 2022, 5:17 p.m. UTC | #2
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:
  

Patch

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();
+};