From patchwork Fri May 10 14:17:37 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Merrill X-Patchwork-Id: 242994 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]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client CN "localhost", Issuer "www.qmailtoaster.com" (not verified)) by ozlabs.org (Postfix) with ESMTPS id 749B12C00B6 for ; Sat, 11 May 2013 00:18:15 +1000 (EST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :message-id:date:from:mime-version:to:subject:content-type; q= dns; s=default; b=Y0ANkAuqGOTqZCN9mRVyk4JKCaeAlelq63gCLPZFReANmz xowHL1uXiN5f0WtALMjCyHJVxRRDDR97w2ArV3tQvSx4l0wC0LjP2fsqY650GW1T pQ9UeMBO8sqQE20muLFwZ7sSBcPhRG4aS/8BdJ4pSJzlts2+3ozA1pAcyQur8= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :message-id:date:from:mime-version:to:subject:content-type; s= default; bh=88QdSX4JeCOBeh5jao+xXd3VXbg=; b=ZFvyA5mjNbaez6H9/mCb pQYOO2MBGWAVRmjULC/sZjt6TC5GDfkX8gs5cuc9XrzFHeLrO5Xe6HkQ5dO+tx+I ljJK9rT6I/k6HSDKxZfBfBPGzmcuBlXTMjMNHJurxXtjPzgRV5AaCfqVWDI5gAsf 9g2LYiSJbphwKyA+n/57/jM= Received: (qmail 8288 invoked by alias); 10 May 2013 14:17:41 -0000 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 Received: (qmail 8256 invoked by uid 89); 10 May 2013 14:17:40 -0000 X-Spam-SWARE-Status: No, score=-7.1 required=5.0 tests=AWL, BAYES_00, RCVD_IN_HOSTKARMA_W, RCVD_IN_HOSTKARMA_WL, RP_MATCHES_RCVD, SPF_HELO_PASS, SPF_PASS autolearn=ham version=3.3.1 Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.84/v0.84-167-ge50287c) with ESMTP; Fri, 10 May 2013 14:17:39 +0000 Received: from int-mx12.intmail.prod.int.phx2.redhat.com (int-mx12.intmail.prod.int.phx2.redhat.com [10.5.11.25]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id r4AEHcK2007037 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Fri, 10 May 2013 10:17:38 -0400 Received: from [10.3.113.45] (ovpn-113-45.phx2.redhat.com [10.3.113.45]) by int-mx12.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id r4AEHb2M029739 for ; Fri, 10 May 2013 10:17:37 -0400 Message-ID: <518D0181.7000101@redhat.com> Date: Fri, 10 May 2013 10:17:37 -0400 From: Jason Merrill User-Agent: Mozilla/5.0 (X11; Linux i686; rv:22.0) Gecko/20100101 Thunderbird/22.0a2 MIME-Version: 1.0 To: gcc-patches List Subject: C++ PATCH for c++/55149 (VLA lambda capture) X-Virus-Found: No This bug talks about ICEs trying to capture a VLA by value. We don't support that, but we can give a more helpful error. In the comments Paolo also noticed that with the new support for capture by reference, we wrongly warn about returning a reference to the captured variable. Tested x86_64-pc-linux-gnu, applying to trunk. commit e88823b454079098df61d1701ac0c7b59a96b758 Author: Jason Merrill Date: Thu May 9 22:15:22 2013 -0400 PR c++/55149 * semantics.c (add_capture): Error rather than abort on copy capture of VLA. * typeck.c (maybe_warn_about_returning_address_of_local): Don't warn about capture proxy. diff --git a/gcc/cp/semantics.c b/gcc/cp/semantics.c index 3e1a0bf..d0db10a 100644 --- a/gcc/cp/semantics.c +++ b/gcc/cp/semantics.c @@ -9463,9 +9463,12 @@ add_capture (tree lambda, tree id, tree initializer, bool by_reference_p, type = lambda_capture_field_type (initializer, explicit_init_p); if (array_of_runtime_bound_p (type)) { + if (!by_reference_p) + error ("array of runtime bound cannot be captured by copy, " + "only by reference"); + /* For a VLA, we capture the address of the first element and the maximum index, and then reconstruct the VLA for the proxy. */ - gcc_assert (by_reference_p); tree elt = cp_build_array_ref (input_location, initializer, integer_zero_node, tf_warning_or_error); tree ctype = vla_capture_type (type); diff --git a/gcc/cp/typeck.c b/gcc/cp/typeck.c index df5fc4a..b8ea555 100644 --- a/gcc/cp/typeck.c +++ b/gcc/cp/typeck.c @@ -8140,6 +8140,7 @@ maybe_warn_about_returning_address_of_local (tree retval) if (DECL_P (whats_returned) && DECL_NAME (whats_returned) && DECL_FUNCTION_SCOPE_P (whats_returned) + && !is_capture_proxy (whats_returned) && !(TREE_STATIC (whats_returned) || TREE_PUBLIC (whats_returned))) { diff --git a/gcc/testsuite/g++.dg/cpp1y/vla5.C b/gcc/testsuite/g++.dg/cpp1y/vla5.C new file mode 100644 index 0000000..1f6da29 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp1y/vla5.C @@ -0,0 +1,8 @@ +// PR c++/55149 +// { dg-options -std=c++1y } + +void test(int n) { + int r[n]; + [&r]() { return r + 0; }; + [r]() { return r + 0; }; // { dg-error "captured by copy" } +}