Here we have a forward declaration of Parameter for which we create
an implicit typedef, which is a TYPE_DECL.  Then, when looking it up
at template definition time, cp_parser_template_id gets (since r12-6754)
this TYPE_DECL which it can't handle.

This patch defers lookup for implicit typedefs, a la r12-6879.

Bootstrapped/regtested on x86_64-pc-linux-gnu, ok for trunk?

        PR c++/104608

gcc/cp/ChangeLog:

        * parser.cc (cp_parser_template_name): Repeat lookup of implicit
        typedef.

gcc/testsuite/ChangeLog:

        * g++.dg/parse/template-keyword3.C: New test.
---
 gcc/cp/parser.cc                               |  3 ++-
 gcc/testsuite/g++.dg/parse/template-keyword3.C | 12 ++++++++++++
 2 files changed, 14 insertions(+), 1 deletion(-)
 create mode 100644 gcc/testsuite/g++.dg/parse/template-keyword3.C

diff --git a/gcc/cp/parser.cc b/gcc/cp/parser.cc
index 03d99aba13e..5e89e3737b0 100644
--- a/gcc/cp/parser.cc
+++ b/gcc/cp/parser.cc
@@ -18681,7 +18681,8 @@ cp_parser_template_name (cp_parser* parser,
          return error_mark_node;
        }
       else if ((!DECL_P (decl) && !is_overloaded_fn (decl))
-              || TREE_CODE (decl) == USING_DECL)
+              || TREE_CODE (decl) == USING_DECL
+              || DECL_IMPLICIT_TYPEDEF_P (decl))
        /* Repeat the lookup at instantiation time.  */
        decl = identifier;
     }
diff --git a/gcc/testsuite/g++.dg/parse/template-keyword3.C 
b/gcc/testsuite/g++.dg/parse/template-keyword3.C
new file mode 100644
index 00000000000..59fe0fc180b
--- /dev/null
+++ b/gcc/testsuite/g++.dg/parse/template-keyword3.C
@@ -0,0 +1,12 @@
+// PR c++/104608
+
+class Parameter;
+template <typename R> class Function 
+: public R  
+{
+    Function();
+};
+template <typename R>
+Function<R>::Function() {
+    this->template Parameter<R>();
+}

base-commit: bc66b471d16ef2fd8cb66fd1131b41f80ecb9961
-- 
2.35.1

Reply via email to