From patchwork Thu Mar 28 18:11:52 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Merrill X-Patchwork-Id: 232158 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 332E42C00A9 for ; Fri, 29 Mar 2013 05:12:14 +1100 (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=gxjnMqHzeXP9DdbCWXBD7tIf6sUHJ4o1Y66afgXcKEbcWP qSAe6f/P47wO//DkoFTIvarGPmGeMiq60W5uOTT6Yl/FvaJdvHhtuDOeX+vWB3xF iC2VAI6Th8fydfebLcB40hXICgjEnoXVPIb7HbdPDFl57e1MTXPTiTT0llDbw= 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=U+Wq7BJRhRKnMQmAn38A4582dv8=; b=ie8NSWgdPDdXCBFxLqN2 de4c+dX88JAZmFomu5alCYHZTK51n3VRhNBYxSmW8D+ud9Wyw2TyMg7gGsVVBLMO oDYe3hgYtADVrVfUCH+HeWy91+LVRpmeHCyLe2t+0eGbIGv0u6iX9QBVmLm8m+y1 FPk5ImIuI7z1kEzoLDpuh7A= Received: (qmail 18761 invoked by alias); 28 Mar 2013 18:12:03 -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 18729 invoked by uid 89); 28 Mar 2013 18:11:57 -0000 X-Spam-SWARE-Status: No, score=-7.1 required=5.0 tests=AWL, BAYES_00, KHOP_RCVD_UNTRUST, RCVD_IN_DNSWL_HI, RCVD_IN_HOSTKARMA_W, RP_MATCHES_RCVD, SPF_HELO_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; Thu, 28 Mar 2013 18:11:54 +0000 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id r2SIBrCG022422 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Thu, 28 Mar 2013 14:11:53 -0400 Received: from [10.16.196.202] (wlan-196-202.bos.redhat.com [10.16.196.202]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id r2SIBqY6024602 for ; Thu, 28 Mar 2013 14:11:53 -0400 Message-ID: <515487E8.8070803@redhat.com> Date: Thu, 28 Mar 2013 14:11:52 -0400 From: Jason Merrill User-Agent: Mozilla/5.0 (X11; Linux i686; rv:21.0) Gecko/20100101 Thunderbird/21.0a2 MIME-Version: 1.0 To: gcc-patches List Subject: C++ PATCH for c++/56710 (ICE with local variable __t in lambda) X-Virus-Found: No The compiler was getting confused when an implicit capture added a __t class binding and then tried to pop the __t local variable. But we don't need to push the closure members as bindings at all, since we now use capture proxies for name resolution. The second patch fixes a -Wshadow issue I noticed while looking at this. Tested x86_64-pc-linux-gnu, applying to trunk. commit 03426fb7d994c8eb6bf7f1097c45f6079e8227d5 Author: Jason Merrill Date: Wed Mar 27 15:47:58 2013 -0400 PR c++/56710 * semantics.c (finish_member_declaration): Don't push closure members. diff --git a/gcc/cp/semantics.c b/gcc/cp/semantics.c index 0b8e2f7..ad1c209 100644 --- a/gcc/cp/semantics.c +++ b/gcc/cp/semantics.c @@ -2719,8 +2719,10 @@ finish_member_declaration (tree decl) /*friend_p=*/0); } } - /* Enter the DECL into the scope of the class. */ - else if (pushdecl_class_level (decl)) + /* Enter the DECL into the scope of the class, if the class + isn't a closure (whose fields are supposed to be unnamed). */ + else if (CLASSTYPE_LAMBDA_EXPR (current_class_type) + || pushdecl_class_level (decl)) { if (TREE_CODE (decl) == USING_DECL) { diff --git a/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-names1.C b/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-names1.C new file mode 100644 index 0000000..df2b037 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-names1.C @@ -0,0 +1,9 @@ +// PR c++/56710 +// { dg-options "-std=c++11 -Wall" } + +int main() +{ + int t = 0; + return [&]() -> int {int __t; __t = t; return __t; }(); + return [&t]() -> int {int __t; __t = t; return __t; }(); +} commit db4f00892384f76f442401984007eb2a0b476eb2 Author: Jason Merrill Date: Wed Mar 27 15:31:09 2013 -0400 * name-lookup.c (pushdecl_maybe_friend_1): Use nonlambda_method_basetype and current_nonlambda_class_type. diff --git a/gcc/cp/name-lookup.c b/gcc/cp/name-lookup.c index 0a0915a..e2ef75b 100644 --- a/gcc/cp/name-lookup.c +++ b/gcc/cp/name-lookup.c @@ -1163,8 +1163,8 @@ pushdecl_maybe_friend_1 (tree x, bool is_friend) { tree member; - if (current_class_ptr) - member = lookup_member (current_class_type, + if (nonlambda_method_basetype ()) + member = lookup_member (current_nonlambda_class_type (), name, /*protect=*/0, /*want_type=*/false, diff --git a/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-shadow2.C b/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-shadow2.C new file mode 100644 index 0000000..8237a81 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-shadow2.C @@ -0,0 +1,10 @@ +// { dg-options "-std=c++11 -Wshadow" } + +struct A +{ + int i; + void f() + { + [=]{ int i; }; // { dg-warning "shadows" } + } +};