From patchwork Thu Jun 10 06:40:29 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [c++] Fix pr22138 Date: Wed, 09 Jun 2010 20:40:29 -0000 From: Shujing Zhao X-Patchwork-Id: 55157 Message-Id: <4C1088DD.1060400@oracle.com> To: GCC Patches Cc: Gabriel Dos Reis , Paolo Carlini Hi, This patch is to fix pr22138. It would error "local template declarations is not allowed" instead of "expected primary-expression before 'template'". The "expected ‘;’ before ‘template’" error would not be output too. Bootstrapped and tested on i686-pc-linux-gnu. Is it ok? Thanks Pearly gcc/cp/ 2010-06-10 Shujing Zhao PR c++/22138 * parser.c (cp_parser_primary_expression): Error if local template is declared. gcc/testsuite/ 2010-06-10 Shujing Zhao PR c++/22138 * g++.dg/parse/template25.C: New. Index: cp/parser.c =================================================================== --- cp/parser.c (revision 160431) +++ cp/parser.c (working copy) @@ -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; Index: testsuite/g++.dg/parse/template25.C =================================================================== --- testsuite/g++.dg/parse/template25.C (revision 0) +++ testsuite/g++.dg/parse/template25.C (revision 0) @@ -0,0 +1,8 @@ +// PR c++/22318 +// { dg-do compile } +void f(void) +{ + template class A /* { dg-error "local template declarations is not allowed" } */ + { + }; +}