From patchwork Mon Oct 15 18:33:33 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Carlini X-Patchwork-Id: 191625 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 1D4B22C00B0 for ; Tue, 16 Oct 2012 05:33:57 +1100 (EST) Comment: DKIM? See http://www.dkim.org DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=gcc.gnu.org; s=default; x=1350930838; h=Comment: DomainKey-Signature:Received:Received:Received:Received:Received: Received:Received:Message-ID:Date:From:User-Agent:MIME-Version: To:CC:Subject:References:In-Reply-To:Content-Type:Mailing-List: Precedence:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:Sender:Delivered-To; bh=xmoEBsDPBrNTHhtAxX73qmizIuo=; b=HHwbqxJsJUKahPSinnZkcPGNxZjZrYJedO6m1muHZWlmn52cDdTfB2KDJTfJvY ID0xDi5ir9tz1r/tRqjNdO4kVNAC3oV5hF+ha9ZYev5LvvR4oG8A4ZYHEy5xon67 WC2ccDfkRquvHmZ0sJ1+Gf2xPATpeT3lthAeNeVEFUw8s= Comment: DomainKeys? See http://antispam.yahoo.com/domainkeys DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=default; d=gcc.gnu.org; h=Received:Received:X-SWARE-Spam-Status:X-Spam-Check-By:Received:Received:Received:Received:Received:Message-ID:Date:From:User-Agent:MIME-Version:To:CC:Subject:References:In-Reply-To:Content-Type:X-IsSubscribed:Mailing-List:Precedence:List-Id:List-Unsubscribe:List-Archive:List-Post:List-Help:Sender:Delivered-To; b=YQ/zs9zlOqsFZNVfuI3go3xiDUrvoDfWpIfxSYtvNXSe7CaBzRkiPUsMQI6Pvs Os2dJwHfYYh8iMd2mFXFDmYqrd/EumQn+iT7jNQE/Hl9rCad8tBu/QdUn4bT0IEX zQvtSYcF4/4ySgiKR+17GhSBmtPLY5RdG0M3Tz7hK61HQ=; Received: (qmail 19428 invoked by alias); 15 Oct 2012 18:33:46 -0000 Received: (qmail 19418 invoked by uid 22791); 15 Oct 2012 18:33:44 -0000 X-SWARE-Spam-Status: No, hits=-7.8 required=5.0 tests=AWL, BAYES_00, KHOP_RCVD_UNTRUST, KHOP_THREADED, RCVD_IN_DNSWL_HI, RCVD_IN_HOSTKARMA_NO, RCVD_IN_HOSTKARMA_YE, RP_MATCHES_RCVD, TW_CX X-Spam-Check-By: sourceware.org Received: from acsinet15.oracle.com (HELO acsinet15.oracle.com) (141.146.126.227) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Mon, 15 Oct 2012 18:33:40 +0000 Received: from acsinet22.oracle.com (acsinet22.oracle.com [141.146.126.238]) by acsinet15.oracle.com (Sentrion-MTA-4.2.2/Sentrion-MTA-4.2.2) with ESMTP id q9FIXb2R030163 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Mon, 15 Oct 2012 18:33:37 GMT Received: from acsmt357.oracle.com (acsmt357.oracle.com [141.146.40.157]) by acsinet22.oracle.com (8.14.4+Sun/8.14.4) with ESMTP id q9FIXa3s008159 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Mon, 15 Oct 2012 18:33:36 GMT Received: from abhmt102.oracle.com (abhmt102.oracle.com [141.146.116.54]) by acsmt357.oracle.com (8.12.11.20060308/8.12.11) with ESMTP id q9FIXaJk009458; Mon, 15 Oct 2012 13:33:36 -0500 Received: from [192.168.1.4] (/79.25.197.253) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Mon, 15 Oct 2012 11:33:36 -0700 Message-ID: <507C56FD.7070003@oracle.com> Date: Mon, 15 Oct 2012 20:33:33 +0200 From: Paolo Carlini User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:15.0) Gecko/20120825 Thunderbird/15.0 MIME-Version: 1.0 To: Jason Merrill CC: "gcc-patches@gcc.gnu.org" Subject: Re: [C++ Patch] PR 50080 References: <507C26A1.4060001@oracle.com> <507C39DE.3060307@redhat.com> <507C4851.5000102@redhat.com> In-Reply-To: <507C4851.5000102@redhat.com> 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 On 10/15/2012 07:30 PM, Jason Merrill wrote: > Actually, let's keep the diagnostic when compiling with -pedantic in > 98 mode. ... too late! ;) So I prepared the below, I'm finishing testing it. Thanks, Paolo. ////////////////// /cp 2012-10-15 Paolo Carlini PR c++/50080 (again) * parser.c (cp_parser_optional_template_keyword): When -pedantic and C++98 mode restore pre-Core/468 behavior. /testsuite 2012-10-15 Paolo Carlini PR c++/50080 (again) * g++.dg/parse/tmpl-outside2.C: Tweak, error in C++98. * g++.dg/parse/tmpl-outside1.C: Likewise. * g++.dg/template/qualttp18.C: Likewise. * g++.old-deja/g++.pt/memtemp87.C: Likewise. * g++.old-deja/g++.pt/overload13.C: Likewise. Index: cp/parser.c =================================================================== --- cp/parser.c (revision 192465) +++ cp/parser.c (working copy) @@ -23252,9 +23252,29 @@ cp_parser_optional_template_keyword (cp_parser *pa { if (cp_lexer_next_token_is_keyword (parser->lexer, RID_TEMPLATE)) { - /* Consume the `template' keyword. */ - cp_lexer_consume_token (parser->lexer); - return true; + /* In C++98 the `template' keyword can only be used within templates; + outside templates the parser can always figure out what is a + template and what is not. In C++11, per the resolution of DR 468, + 'template' is allowed in cases where it is not strictly necessary. */ + if (!processing_template_decl + && pedantic && cxx_dialect == cxx98) + { + cp_token *token = cp_lexer_peek_token (parser->lexer); + error_at (token->location, + "in C++98 % (as a disambiguator) is only " + "allowed within templates"); + /* If this part of the token stream is rescanned, the same + error message would be generated. So, we purge the token + from the stream. */ + cp_lexer_purge_token (parser->lexer); + return false; + } + else + { + /* Consume the `template' keyword. */ + cp_lexer_consume_token (parser->lexer); + return true; + } } return false; } Index: testsuite/g++.old-deja/g++.pt/overload13.C =================================================================== --- testsuite/g++.old-deja/g++.pt/overload13.C (revision 192465) +++ testsuite/g++.old-deja/g++.pt/overload13.C (working copy) @@ -7,5 +7,5 @@ struct A { int main () { A a; - return a.template f (0); + return a.template f (0); // { dg-error "template" "" { target c++98 } } } Index: testsuite/g++.old-deja/g++.pt/memtemp87.C =================================================================== --- testsuite/g++.old-deja/g++.pt/memtemp87.C (revision 192465) +++ testsuite/g++.old-deja/g++.pt/memtemp87.C (working copy) @@ -12,4 +12,4 @@ class Q { template class> class Y { }; -Q::template X x; +Q::template X x; // { dg-error "template" "" { target c++98 } } Index: testsuite/g++.dg/parse/tmpl-outside1.C =================================================================== --- testsuite/g++.dg/parse/tmpl-outside1.C (revision 192465) +++ testsuite/g++.dg/parse/tmpl-outside1.C (working copy) @@ -7,4 +7,4 @@ struct X template struct Y {}; }; -typedef X::template Y<0> y; +typedef X::template Y<0> y; // { dg-error "template|invalid" "" { target c++98 } } Index: testsuite/g++.dg/parse/tmpl-outside2.C =================================================================== --- testsuite/g++.dg/parse/tmpl-outside2.C (revision 192465) +++ testsuite/g++.dg/parse/tmpl-outside2.C (working copy) @@ -15,5 +15,5 @@ void test() int main() { - typename A::template B b; + typename A::template B b; // { dg-error "template|expected" "" { target c++98 } } } Index: testsuite/g++.dg/template/qualttp18.C =================================================================== --- testsuite/g++.dg/template/qualttp18.C (revision 192465) +++ testsuite/g++.dg/template/qualttp18.C (working copy) @@ -14,7 +14,7 @@ template