[pushed] c++: friend with redundant qualification [PR41723]

Message ID 20210407213419.1769976-1-jason@redhat.com
State New
Headers show
Series
  • [pushed] c++: friend with redundant qualification [PR41723]
Related show

Commit Message

Paul Richard Thomas via Gcc-patches April 7, 2021, 9:34 p.m.
Different code paths were correctly choosing to look up D directly, since C
is the current instantiation, but here we decided to try to make it a
typename type, leading to confusion.  Fixed by using dependent_scope_p as we
do elsewhere.

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

gcc/cp/ChangeLog:

	PR c++/41723
	* parser.c (cp_parser_class_name): Check dependent_scope_p.

gcc/testsuite/ChangeLog:

	PR c++/41723
	* g++.dg/template/friend71.C: New test.
---
 gcc/cp/parser.c                          | 2 +-
 gcc/testsuite/g++.dg/template/friend71.C | 8 ++++++++
 2 files changed, 9 insertions(+), 1 deletion(-)
 create mode 100644 gcc/testsuite/g++.dg/template/friend71.C


base-commit: a528594cf9a74e5a0fbac13ef673064ed73e1b89
prerequisite-patch-id: 6c2b63b290a1c22c08dd307fcd872aeb647f67a5
-- 
2.27.0

Patch

diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c
index c915d6415de..59adac4492a 100644
--- a/gcc/cp/parser.c
+++ b/gcc/cp/parser.c
@@ -24639,7 +24639,7 @@  cp_parser_class_name (cp_parser *parser,
   const bool typename_p = (typename_keyword_p
 			   && parser->scope
 			   && TYPE_P (parser->scope)
-			   && dependent_type_p (parser->scope));
+			   && dependent_scope_p (parser->scope));
   /* Handle the common case (an identifier, but not a template-id)
      efficiently.  */
   if (token->type == CPP_NAME
diff --git a/gcc/testsuite/g++.dg/template/friend71.C b/gcc/testsuite/g++.dg/template/friend71.C
new file mode 100644
index 00000000000..939ea6b5264
--- /dev/null
+++ b/gcc/testsuite/g++.dg/template/friend71.C
@@ -0,0 +1,8 @@ 
+// PR c++/41723
+
+template<class T>
+class C {
+  template <class U> class D {};
+
+  friend class C::D<int>;
+};