From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 24624 invoked by alias); 12 Nov 2008 14:33:52 -0000 Received: (qmail 24557 invoked by uid 22791); 12 Nov 2008 14:33:49 -0000 X-Spam-Check-By: sourceware.org Received: from mx1.redhat.com (HELO mx1.redhat.com) (66.187.233.31) by sourceware.org (qpsmtpd/0.31) with ESMTP; Wed, 12 Nov 2008 14:33:02 +0000 Received: from int-mx1.corp.redhat.com (int-mx1.corp.redhat.com [172.16.52.254]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id mACEUCnm010923; Wed, 12 Nov 2008 09:30:12 -0500 Received: from tyan-ft48-01.lab.bos.redhat.com (tyan-ft48-01.lab.bos.redhat.com [10.16.42.4]) by int-mx1.corp.redhat.com (8.13.1/8.13.1) with ESMTP id mACEU9Ld004574; Wed, 12 Nov 2008 09:30:09 -0500 Received: (from jakub@localhost) by tyan-ft48-01.lab.bos.redhat.com (8.14.2/8.14.2/Submit) id mACEU8vW012112; Wed, 12 Nov 2008 15:30:08 +0100 Date: Wed, 12 Nov 2008 15:19:00 -0000 From: Jakub Jelinek To: Mark Mitchell , Jason Merrill Cc: gcc-patches@gcc.gnu.org Subject: [C++ PATCH] Don't commit to tentative parse in cp_parser_simple_declaration if there were parse errors (PR c++/34269) Message-ID: <20081112143008.GP3572@tyan-ft48-01.lab.bos.redhat.com> Reply-To: Jakub Jelinek MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.5.18 (2008-05-17) X-IsSubscribed: yes Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org X-SW-Source: 2008-11/txt/msg00518.txt.bz2 Hi! If there were parse errors, not committing to tentative parse means it will be parsed again as expression and diagnostics emitted. Bootstrapped/regtested on x86_64-linux, ok for trunk? 2008-11-12 Jakub Jelinek PR c++/34269 * parser.c (cp_parser_simple_declaration): Don't commit to tentative parse if parse errors were seen. * g++.dg/cpp0x/decltype13.C: New test. * g++.dg/cpp0x/decltype-33837.C: Adjust dg-error pattern. * g++.dg/cpp0x/pr33839.C: Likewise. --- gcc/cp/parser.c.jj 2008-11-10 11:34:14.000000000 +0100 +++ gcc/cp/parser.c 2008-11-12 13:08:26.000000000 +0100 @@ -8174,7 +8174,8 @@ cp_parser_simple_declaration (cp_parser* (After "int (" we might be looking at a functional cast.) */ if (decl_specifiers.any_specifiers_p && cp_lexer_next_token_is_not (parser->lexer, CPP_OPEN_PAREN) - && cp_lexer_next_token_is_not (parser->lexer, CPP_OPEN_BRACE)) + && cp_lexer_next_token_is_not (parser->lexer, CPP_OPEN_BRACE) + && !cp_parser_error_occurred (parser)) cp_parser_commit_to_tentative_parse (parser); /* Keep going until we hit the `;' at the end of the simple --- gcc/testsuite/g++.dg/cpp0x/decltype13.C.jj 2008-11-12 13:14:14.000000000 +0100 +++ gcc/testsuite/g++.dg/cpp0x/decltype13.C 2008-11-12 13:12:44.000000000 +0100 @@ -0,0 +1,38 @@ +// PR c++/34269 +// { dg-do compile } + +void +f1 () +{ + __decltype; // { dg-error "expected" } +} + +void +f2 () +{ + __decltype (; // { dg-error "expected" } +} + +void +f3 () +{ + __decltype (); // { dg-error "expected" } +} + +void +f4 () +{ + __typeof__; // { dg-error "expected" } +} + +void +f5 () +{ + __typeof__ (; // { dg-error "expected" } +} + +void +f6 () +{ + __typeof__ (); // { dg-error "expected" } +} --- gcc/testsuite/g++.dg/cpp0x/decltype-33837.C.jj 2008-11-12 13:19:16.000000000 +0100 +++ gcc/testsuite/g++.dg/cpp0x/decltype-33837.C 2008-11-12 13:19:16.000000000 +0100 @@ -2,6 +2,6 @@ // PR c++/33837 void foo() { - __decltype (A::foo()); // { dg-error "was not declared|expected initializer" } + __decltype (A::foo()); // { dg-error "was not declared|expected" } __decltype (B); // { dg-error "was not declared" } } --- gcc/testsuite/g++.dg/cpp0x/pr33839.C.jj 2008-09-05 12:55:05.000000000 +0200 +++ gcc/testsuite/g++.dg/cpp0x/pr33839.C 2008-11-12 13:18:14.000000000 +0100 @@ -3,6 +3,6 @@ template struct A; void foo() { - __decltype A<0>; // { dg-error "invalid declarator" } + __decltype A<0>; // { dg-error "invalid declarator|expected" } __decltype (A<0>); // { dg-error "must be an expression" } } Jakub