From patchwork Thu May 24 10:27:28 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Carlini X-Patchwork-Id: 161113 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 6CE08B6FD7 for ; Thu, 24 May 2012 20:29:03 +1000 (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=1338460146; h=Comment: DomainKey-Signature:Received:Received:Received:Received:Received: Received:Received:Message-ID:Date:From:User-Agent:MIME-Version: To:CC:Subject:Content-Type:Mailing-List:Precedence:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:Sender: Delivered-To; bh=I8KIcpLXvI/tEs1fwzbYyJCckBw=; b=i0Ef9Z71Q6Gw9Jp +byJ3V8R0UMiSvHSd/qLC/bIdnXl4gUNl9/DqkZVedgTXIZ8icE24GCNMSEGYDvX q9Prk+sqZ9+UuJJ57vzIgxRfDSjP7o4RONlWCSZ8b/O8tL7G6EEBg7tNhF09Y3aK Hh1O24rGOo2TpyyTEIIt3BWTjaKM= 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:Content-Type:X-IsSubscribed:Mailing-List:Precedence:List-Id:List-Unsubscribe:List-Archive:List-Post:List-Help:Sender:Delivered-To; b=AG7s4OG5P0ccIhPuJqblkdPpd6tm5ygHd5r3UmOjt4haUFpMmu/pH+HuNhS/Wp k7G1aWi0BaLn90UodcehJPwXhRcDu09v0vOr/cAD4sw5wFlGuo6z8oUlNqdmq9jM RjjyrZyU35WJrHrRqIjRtBvGsXvA2j8tAhjroTnPzXoOo=; Received: (qmail 20555 invoked by alias); 24 May 2012 10:28:57 -0000 Received: (qmail 20542 invoked by uid 22791); 24 May 2012 10:28:55 -0000 X-SWARE-Spam-Status: No, hits=-6.6 required=5.0 tests=AWL, BAYES_00, KHOP_RCVD_UNTRUST, RCVD_IN_DNSWL_HI, RCVD_IN_HOSTKARMA_NO, RCVD_IN_HOSTKARMA_W, T_RP_MATCHES_RCVD 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; Thu, 24 May 2012 10:28:42 +0000 Received: from acsinet21.oracle.com (acsinet21.oracle.com [141.146.126.237]) by acsinet15.oracle.com (Sentrion-MTA-4.2.2/Sentrion-MTA-4.2.2) with ESMTP id q4OASdH0008753 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Thu, 24 May 2012 10:28:40 GMT Received: from acsmt358.oracle.com (acsmt358.oracle.com [141.146.40.158]) by acsinet21.oracle.com (8.14.4+Sun/8.14.4) with ESMTP id q4OASc3u010526 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Thu, 24 May 2012 10:28:39 GMT Received: from abhmt115.oracle.com (abhmt115.oracle.com [141.146.116.67]) by acsmt358.oracle.com (8.12.11.20060308/8.12.11) with ESMTP id q4OAScle021387; Thu, 24 May 2012 05:28:38 -0500 Received: from [192.168.1.4] (/79.33.217.194) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Thu, 24 May 2012 03:28:38 -0700 Message-ID: <4FBE0D10.5030502@oracle.com> Date: Thu, 24 May 2012 12:27:28 +0200 From: Paolo Carlini User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:12.0) Gecko/20120421 Thunderbird/12.0 MIME-Version: 1.0 To: "gcc-patches@gcc.gnu.org" CC: Jason Merrill Subject: [C++ Patch] PR 32080 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, the issue here is that we don't diagnose jumps into the try of a function-try-block. The reason is quite simple: from cp_parser_function_try_block we call cp_parser_ctor_initializer_opt_and_function_body which calls cp_parser_function_body, which always passes false to cp_parser_compound_statement as third argument. Thus it seems to me that the straightforward way to fix this is making sure a true reaches the latter when parsing a function-try-block, then it must work because try-blocks do exactly that and are already fine. Bootstrapped and tested x86_64-linux. Thanks, Paolo. /////////////////////// /cp 2012-05-24 Paolo Carlini PR c++/32080 * parser.c (cp_parser_ctor_initializer_opt_and_function_body, cp_parser_function_body): Add a bool parameter, true when parsing a function-try-block. (cp_parser_function_try_block): Pass true to the above. (cp_parser_function_definition_after_declarator, cp_parser_function_transaction): Adjust. /testsuite 2012-05-24 Paolo Carlini PR c++/32080 * g++.dg/eh/goto2.C: New. Index: testsuite/g++.dg/eh/goto2.C =================================================================== --- testsuite/g++.dg/eh/goto2.C (revision 0) +++ testsuite/g++.dg/eh/goto2.C (revision 0) @@ -0,0 +1,12 @@ +// PR c++/32080 + +void f() +try + { + goto l2; // { dg-error "from here" } + l1: ; // { dg-error "jump to label 'l1'" } + } catch (...) + { + l2: ; // { dg-error "jump to label 'l2'|enters catch block" } + goto l1; // { dg-error "from here|enters try block" } + } Index: cp/parser.c =================================================================== --- cp/parser.c (revision 187822) +++ cp/parser.c (working copy) @@ -1989,7 +1989,7 @@ static cp_parameter_declarator *cp_parser_paramete static tree cp_parser_default_argument (cp_parser *, bool); static void cp_parser_function_body - (cp_parser *); + (cp_parser *, bool); static tree cp_parser_initializer (cp_parser *, bool *, bool *); static tree cp_parser_initializer_clause @@ -2000,7 +2000,7 @@ static VEC(constructor_elt,gc) *cp_parser_initiali (cp_parser *, bool *); static bool cp_parser_ctor_initializer_opt_and_function_body - (cp_parser *); + (cp_parser *, bool); /* Classes [gram.class] */ @@ -17395,16 +17395,18 @@ cp_parser_default_argument (cp_parser *parser, boo compound_statement */ static void -cp_parser_function_body (cp_parser *parser) +cp_parser_function_body (cp_parser *parser, bool in_function_try_block) { - cp_parser_compound_statement (parser, NULL, false, true); + cp_parser_compound_statement (parser, NULL, in_function_try_block, true); } /* Parse a ctor-initializer-opt followed by a function-body. Return - true if a ctor-initializer was present. */ + true if a ctor-initializer was present. When IN_FUNCTION_TRY_BLOCK + is true we are parsing a function-try-block. */ static bool -cp_parser_ctor_initializer_opt_and_function_body (cp_parser *parser) +cp_parser_ctor_initializer_opt_and_function_body (cp_parser *parser, + bool in_function_try_block) { tree body, list; bool ctor_initializer_p; @@ -17431,7 +17433,7 @@ static bool last = STATEMENT_LIST_TAIL (list)->stmt; } /* Parse the function-body. */ - cp_parser_function_body (parser); + cp_parser_function_body (parser, in_function_try_block); if (check_body_p) check_constexpr_ctor_body (last, list); /* Finish the function body. */ @@ -19707,8 +19709,8 @@ cp_parser_function_try_block (cp_parser* parser) /* Let the rest of the front end know where we are. */ try_block = begin_function_try_block (&compound_stmt); /* Parse the function-body. */ - ctor_initializer_p - = cp_parser_ctor_initializer_opt_and_function_body (parser); + ctor_initializer_p = cp_parser_ctor_initializer_opt_and_function_body + (parser, /*in_function_try_block=*/true); /* We're done with the `try' part. */ finish_function_try_block (try_block); /* Parse the handlers. */ @@ -21048,8 +21050,8 @@ cp_parser_function_definition_after_declarator (cp else if (cp_lexer_next_token_is_keyword (parser->lexer, RID_TRY)) ctor_initializer_p = cp_parser_function_try_block (parser); else - ctor_initializer_p - = cp_parser_ctor_initializer_opt_and_function_body (parser); + ctor_initializer_p = cp_parser_ctor_initializer_opt_and_function_body + (parser, /*in_function_try_block=*/false); finish_lambda_scope (); @@ -27224,8 +27226,8 @@ cp_parser_function_transaction (cp_parser *parser, if (cp_lexer_next_token_is_keyword (parser->lexer, RID_TRY)) ctor_initializer_p = cp_parser_function_try_block (parser); else - ctor_initializer_p - = cp_parser_ctor_initializer_opt_and_function_body (parser); + ctor_initializer_p = cp_parser_ctor_initializer_opt_and_function_body + (parser, /*in_function_try_block=*/false); parser->in_transaction = old_in;