diff --git a/gcc/cp/parser.cc b/gcc/cp/parser.cc index 18db9d40a01..87b9781e793 100644 --- a/gcc/cp/parser.cc +++ b/gcc/cp/parser.cc @@ -18674,7 +18674,10 @@ 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 + /* 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; } 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 class Function +: public R +{ + Function(); +}; +template +Function::Function() { + this->template Parameter(); +} diff --git a/gcc/testsuite/g++.dg/parse/template-keyword4.C b/gcc/testsuite/g++.dg/parse/template-keyword4.C new file mode 100644 index 00000000000..c688094bcf2 --- /dev/null +++ b/gcc/testsuite/g++.dg/parse/template-keyword4.C @@ -0,0 +1,17 @@ +// PR c++/104608 +// { dg-do compile { target c++11 } } + +class S; +using Parameter = S; +typedef S Parameter2; + +template class Function +: public R +{ + Function(); +}; +template +Function::Function() { + this->template Parameter(); + this->template Parameter2(); +}