From patchwork Mon May 7 16:16:20 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Paolo Carlini X-Patchwork-Id: 157348 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 BA568B6FA8 for ; Tue, 8 May 2012 02:17:30 +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=1337012252; 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=PbC+R9qaW1DMuA6dhHhHa51P9rM=; b=ff48KboXsEQ5/6l d1aFaJJYpL9jvhwzs3/RlAsVi1bb6OMl2iZ99qicApWP2sM/ahnJR9s57WZYEa8t CKPLd1xglJ9zXjsImvSLYWH7eIDnWaaKeKzZBZ40d+BRU19Mnw8YpiSG7a/X5j5X fvz7aXHLYHp0dwkGBVX5W8TZl0wE= 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=F0zVaQMq/VRuFFA6OYKbpqJ0A0wzZpVz1DWXAYiXsYszAHunshoc5eRobQLwYT LMgkgS+v8MDSmv3D46RZKnXEGmPkI1cBZ+dtsazpqaq4HM3wdG+IyQ0Ta/3z2EbL l+7nKyQEPQOviXoYdDH0UqMobBcQCv2AsaRTFU6R0jcQQ=; Received: (qmail 16884 invoked by alias); 7 May 2012 16:17:24 -0000 Received: (qmail 16866 invoked by uid 22791); 7 May 2012 16:17:22 -0000 X-SWARE-Spam-Status: No, hits=-6.4 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; Mon, 07 May 2012 16:17:00 +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 q47GGwBR010072 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Mon, 7 May 2012 16:16:58 GMT Received: from acsmt356.oracle.com (acsmt356.oracle.com [141.146.40.156]) by acsinet22.oracle.com (8.14.4+Sun/8.14.4) with ESMTP id q47GGv85023612 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Mon, 7 May 2012 16:16:58 GMT Received: from abhmt112.oracle.com (abhmt112.oracle.com [141.146.116.64]) by acsmt356.oracle.com (8.12.11.20060308/8.12.11) with ESMTP id q47GGvja014586; Mon, 7 May 2012 11:16:57 -0500 Received: from [192.168.1.4] (/79.47.193.13) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Mon, 07 May 2012 09:16:57 -0700 Message-ID: <4FA7F554.90003@oracle.com> Date: Mon, 07 May 2012 18:16:20 +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 53158 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, for this testcase: int main() { auto a = []() { return true; }; auto b = []() { return a(); }; // { dg-error "'a' is not captured" } int c, d; while (b() && c < d) { } } we produce meaningless diagnostics for the while loop (stemming from b() but the caret is also in the wrong place, a separate issue): error: invalid operands of types ‘void’ and ‘int’ to binary ‘operator!=’ because nothing notices in cp_parser_lambda_body that cp_parser_expression went wrong, thus finish_return_stmt (expr) is called on expr == error_mark_node. The way I'm handling the problem is by returning false to the caller, cp_parser_lambda_expression, which is already equipped to smoothly handle errors and return back error_mark_node. Tested x86_64-linux. Thanks, Paolo. /////////////////////// /cp 2012-05-07 Paolo Carlini PR c++/53158 * parser.c (cp_parser_lambda_body): Return a boolean, false if cp_parser_expression returns error_mark_node; (cp_parser_lambda_expression): Check the latter. /testsuite 2012-05-07 Paolo Carlini PR c++/53158 * g++.dg/cpp0x/lambda/lambda-err2.C: New. Index: testsuite/g++.dg/cpp0x/lambda/lambda-err2.C =================================================================== --- testsuite/g++.dg/cpp0x/lambda/lambda-err2.C (revision 0) +++ testsuite/g++.dg/cpp0x/lambda/lambda-err2.C (revision 0) @@ -0,0 +1,12 @@ +// PR c++/53158 +// { dg-do compile { target c++11 } } + +int main() +{ + auto a = []() { return true; }; + auto b = []() { return a(); }; // { dg-error "'a' is not captured" } + int c, d; + while (b() && c < d) + { + } +} Index: cp/parser.c =================================================================== --- cp/parser.c (revision 187249) +++ cp/parser.c (working copy) @@ -1848,7 +1848,7 @@ static void cp_parser_lambda_introducer (cp_parser *, tree); static bool cp_parser_lambda_declarator_opt (cp_parser *, tree); -static void cp_parser_lambda_body +static bool cp_parser_lambda_body (cp_parser *, tree); /* Statements [gram.stmt.stmt] */ @@ -8101,7 +8101,7 @@ cp_parser_lambda_expression (cp_parser* parser) ok = cp_parser_lambda_declarator_opt (parser, lambda_expr); if (ok) - cp_parser_lambda_body (parser, lambda_expr); + ok = cp_parser_lambda_body (parser, lambda_expr); else if (cp_parser_require (parser, CPP_OPEN_BRACE, RT_OPEN_BRACE)) cp_parser_skip_to_end_of_block_or_statement (parser); @@ -8466,11 +8466,13 @@ cp_parser_lambda_declarator_opt (cp_parser* parser but which requires special handling. LAMBDA_EXPR is the current representation of the lambda expression. */ -static void +static bool cp_parser_lambda_body (cp_parser* parser, tree lambda_expr) { bool nested = (current_function_decl != NULL_TREE); bool local_variables_forbidden_p = parser->local_variables_forbidden_p; + bool ok = true; + if (nested) push_function_context (); else @@ -8540,6 +8542,8 @@ cp_parser_lambda_body (cp_parser* parser, tree lam cp_parser_require_keyword (parser, RID_RETURN, RT_RETURN); expr = cp_parser_expression (parser, /*cast_p=*/false, &idk); + if (expr == error_mark_node) + ok = false; cp_parser_require (parser, CPP_SEMICOLON, RT_SEMICOLON); cp_parser_require (parser, CPP_CLOSE_BRACE, RT_CLOSE_BRACE); @@ -8579,6 +8583,8 @@ cp_parser_lambda_body (cp_parser* parser, tree lam pop_function_context(); else --function_depth; + + return ok; } /* Statements [gram.stmt.stmt] */