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 TYPE_DECLs that cp_parser_template_id can't
handle, a la r12-6879.
PR c++/104608
gcc/cp/ChangeLog:
* parser.cc (cp_parser_template_name): Repeat lookup of
TYPE_DECLs.
gcc/testsuite/ChangeLog:
* g++.dg/parse/template-keyword3.C: New test.
* g++.dg/parse/template-keyword4.C: New test.
return error_mark_node;
}
else if ((!DECL_P (decl) && !is_overloaded_fn (decl))
- || TREE_CODE (decl) == USING_DECL)
+ || TREE_CODE (decl) == USING_DECL
+ /* cp_parser_template_id can only handle some TYPE_DECLs. */
+ || (TREE_CODE (decl) == TYPE_DECL
+ && TREE_CODE (TREE_TYPE (decl)) != TYPENAME_TYPE))
/* Repeat the lookup at instantiation time. */
decl = identifier;
}
--- /dev/null
+// PR c++/104608
+
+class Parameter;
+template <typename R> class Function
+: public R
+{
+ Function();
+};
+template <typename R>
+Function<R>::Function() {
+ this->template Parameter<R>();
+}
--- /dev/null
+// PR c++/104608
+// { dg-do compile { target c++11 } }
+
+class S;
+using Parameter = S;
+typedef S Parameter2;
+
+template <typename R> class Function
+: public R
+{
+ Function();
+};
+template <typename R>
+Function<R>::Function() {
+ this->template Parameter<R>();
+ this->template Parameter2<R>();
+}