===================================================================
@@ -3754,6 +3754,14 @@ cp_parser_primary_expression (cp_parser
case RID_AT_SELECTOR:
return cp_parser_objc_expression (parser);
+ case RID_TEMPLATE:
+ if (parser->in_function_body)
+ {
+ error_at (token->location,
+ "local template declarations is not allowed");
+ cp_parser_skip_to_end_of_block_or_statement (parser);
+ return error_mark_node;
+ }
default:
cp_parser_error (parser, "expected primary-expression");
return error_mark_node;
===================================================================
@@ -0,0 +1,8 @@
+// PR c++/22318
+// { dg-do compile }
+void f(void)
+{
+ template<typename T> class A /* { dg-error "local template declarations is not allowed" } */
+ {
+ };
+}