From patchwork Tue Jul 5 14:50:22 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Merrill X-Patchwork-Id: 103316 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 E584AB6F6F for ; Wed, 6 Jul 2011 00:50:43 +1000 (EST) Received: (qmail 695 invoked by alias); 5 Jul 2011 14:50:42 -0000 Received: (qmail 682 invoked by uid 22791); 5 Jul 2011 14:50:41 -0000 X-SWARE-Spam-Status: No, hits=-6.4 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_HI, SPF_HELO_PASS, T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Tue, 05 Jul 2011 14:50:24 +0000 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id p65EoNDE002116 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Tue, 5 Jul 2011 10:50:23 -0400 Received: from [127.0.0.1] (ovpn-113-44.phx2.redhat.com [10.3.113.44]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id p65EoNcp028142 for ; Tue, 5 Jul 2011 10:50:23 -0400 Message-ID: <4E1324AE.9090902@redhat.com> Date: Tue, 05 Jul 2011 10:50:22 -0400 From: Jason Merrill User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.2.17) Gecko/20110428 Fedora/3.1.10-1.fc14 Lightning/1.0b2 Thunderbird/3.1.10 MIME-Version: 1.0 To: gcc-patches List Subject: C++ PATCH for c++/49598 (ICE with value capture of reference) 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 Need to convert_from_reference a decl that we're using as a normal expression, as in this case as an initializer. Tested x86_64-pc-linux-gnu, applying to trunk. commit b5c0742c0bfe7fe58dba443d47f880c26eea1b82 Author: Jason Merrill Date: Tue Jul 5 01:13:04 2011 -0400 PR c++/49598 * semantics.c (finish_id_expression): convert_from_reference. diff --git a/gcc/cp/semantics.c b/gcc/cp/semantics.c index 619c058..fa22bc9 100644 --- a/gcc/cp/semantics.c +++ b/gcc/cp/semantics.c @@ -2942,7 +2942,7 @@ finish_id_expression (tree id_expression, tree containing_function = current_function_decl; tree lambda_stack = NULL_TREE; tree lambda_expr = NULL_TREE; - tree initializer = decl; + tree initializer = convert_from_reference (decl); /* Core issue 696: "[At the July 2009 meeting] the CWG expressed support for an approach in which a reference to a local diff --git a/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-ref2.C b/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-ref2.C new file mode 100644 index 0000000..15f1d90 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-ref2.C @@ -0,0 +1,13 @@ +// PR c++/49598 +// { dg-options -std=c++0x } +// { dg-do run } + +int +main() +{ + int i = 10; + int& ir = i; + + if ([=]{ return ir; }() != 10) + return 1; +}