From patchwork Sun Mar 17 01:38:26 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Merrill X-Patchwork-Id: 228260 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 3F00E2C00AD for ; Sun, 17 Mar 2013 12:38:38 +1100 (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=1364089118; h=Comment: DomainKey-Signature:Received:Received:Received:Received:Received: Message-ID:Date:From:User-Agent:MIME-Version:To:Subject: Content-Type:Mailing-List:Precedence:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:Sender:Delivered-To; bh=zV3x6Nx YrUgAbWgZajPbENBpnZI=; b=uswjXYc+TtlmMT9POk9g4Eqb/TA/8T5WqGBpTdD fD/6yNSwZgacwVeSTsPKk7ZaXa49vhjxQhnhB4lyY8y/MOW3rHO1TU8C0f/NnaXF 4qFvhNogDdYca/tjyAi9Z1HoUj4QR/zxDZhIlK8SEfasqLKCuD21slb5ODOXWzkh MSb4= 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:Message-ID:Date:From:User-Agent:MIME-Version:To:Subject:Content-Type:Mailing-List:Precedence:List-Id:List-Unsubscribe:List-Archive:List-Post:List-Help:Sender:Delivered-To; b=il8elQhODFWkzDQi1zbRUpA0apjstfZAuVlv0pdr93ef6HL0Vz3HU7iVejJYKK G8Q1/vff+vYWD75o2wNznX5UuEGfMM7cOtikPK7kg+/refZkeCxbFJGRpXP0jgg4 6Gq6b1XD39RAp4ZyVIShl5KcuVqFeGcaHG4eyqLpcIx7k=; Received: (qmail 14638 invoked by alias); 17 Mar 2013 01:38:34 -0000 Received: (qmail 14428 invoked by uid 22791); 17 Mar 2013 01:38:32 -0000 X-SWARE-Spam-Status: No, hits=-7.6 required=5.0 tests=AWL, BAYES_00, KHOP_RCVD_UNTRUST, RCVD_IN_DNSWL_HI, RCVD_IN_HOSTKARMA_W, RP_MATCHES_RCVD, SPF_HELO_PASS 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; Sun, 17 Mar 2013 01:38:27 +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 r2H1cRaj010769 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Sat, 16 Mar 2013 21:38:27 -0400 Received: from [10.3.113.56] (ovpn-113-56.phx2.redhat.com [10.3.113.56]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id r2H1cQ3C026840 for ; Sat, 16 Mar 2013 21:38:26 -0400 Message-ID: <51451E92.7080302@redhat.com> Date: Sat, 16 Mar 2013 21:38:26 -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++/55357 (-Wshadow and lambdas) 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 The submitter of this PR suggested that we don't want to warn about shadowing of a local variable by a lambda parameter; I think we do, since local variables can be used in lambdas, but we don't want a duplicate warning when we copy the parameter into the conversion thunk. Tested x86_64-pc-linux-gnu, applying to trunk. commit cd911b455722c1b88d21ac7dcb192aae53ef7f16 Author: Jason Merrill Date: Tue Mar 5 14:25:04 2013 -0500 PR c++/55357 * semantics.c (maybe_add_lambda_conv_op): Clear DECL_NAME of copied parms to avoid duplicate -Wshadow warnings. diff --git a/gcc/cp/semantics.c b/gcc/cp/semantics.c index 9d2f3f4..d39469d 100644 --- a/gcc/cp/semantics.c +++ b/gcc/cp/semantics.c @@ -9678,7 +9678,11 @@ maybe_add_lambda_conv_op (tree type) DECL_STATIC_FUNCTION_P (fn) = 1; DECL_ARGUMENTS (fn) = copy_list (DECL_CHAIN (DECL_ARGUMENTS (callop))); for (arg = DECL_ARGUMENTS (fn); arg; arg = DECL_CHAIN (arg)) - DECL_CONTEXT (arg) = fn; + { + /* Avoid duplicate -Wshadow warnings. */ + DECL_NAME (arg) = NULL_TREE; + DECL_CONTEXT (arg) = fn; + } if (nested) DECL_INTERFACE_KNOWN (fn) = 1; diff --git a/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-shadow1.C b/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-shadow1.C new file mode 100644 index 0000000..bb06bfe --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-shadow1.C @@ -0,0 +1,9 @@ +// PR c++/55357 +// { dg-options "-std=c++11 -Wshadow" } + +int main() { + int x = 1; // { dg-warning "shadowed" } + auto const lambda = [](int x) { // { dg-warning "shadows" } + return x; + }; +}