From patchwork Thu Jun 10 06:40:29 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Shujing Zhao X-Patchwork-Id: 55157 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) by ozlabs.org (Postfix) with SMTP id 36975100EE7 for ; Thu, 10 Jun 2010 16:40:27 +1000 (EST) Received: (qmail 31333 invoked by alias); 10 Jun 2010 06:40:26 -0000 Received: (qmail 31321 invoked by uid 22791); 10 Jun 2010 06:40:25 -0000 X-SWARE-Spam-Status: No, hits=-1.8 required=5.0 tests=AWL, BAYES_00, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY X-Spam-Check-By: sourceware.org Received: from rcsinet10.oracle.com (HELO rcsinet10.oracle.com) (148.87.113.121) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Thu, 10 Jun 2010 06:40:17 +0000 Received: from rcsinet15.oracle.com (rcsinet15.oracle.com [148.87.113.117]) by rcsinet10.oracle.com (Switch-3.4.2/Switch-3.4.1) with ESMTP id o5A6eDb0011959 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Thu, 10 Jun 2010 06:40:14 GMT Received: from acsmt354.oracle.com (acsmt354.oracle.com [141.146.40.154]) by rcsinet15.oracle.com (Switch-3.4.2/Switch-3.4.1) with ESMTP id o5A5i4IY001587; Thu, 10 Jun 2010 06:40:12 GMT Received: from abhmt004.oracle.com by acsmt355.oracle.com with ESMTP id 312620891276152004; Wed, 09 Jun 2010 23:40:04 -0700 Received: from dhcp-beijing-cdc-10-182-121-28.cn.oracle.com (/10.182.121.28) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Wed, 09 Jun 2010 23:40:04 -0700 Message-ID: <4C1088DD.1060400@oracle.com> Date: Thu, 10 Jun 2010 14:40:29 +0800 From: Shujing Zhao User-Agent: Thunderbird 2.0.0.24 (X11/20100228) MIME-Version: 1.0 To: GCC Patches CC: Gabriel Dos Reis , Paolo Carlini Subject: [PATCH c++] Fix pr22138 X-IsSubscribed: yes Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org 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" } */ + { + }; +}