From patchwork Mon Apr 23 21:17:23 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Paolo Carlini X-Patchwork-Id: 903173 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-476740-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=oracle.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="jePzGiBu"; dkim-atps=neutral Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 40VK6v0GtKz9rxp for ; Tue, 24 Apr 2018 07:17:41 +1000 (AEST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:to:cc :from:subject:message-id:date:mime-version:content-type; q=dns; s=default; b=NhvdsAFx82E2p4chW2KPOLGyFxEELdgGzOmKMIUjwh2FoFGZsY jFTcfhRuLai31j/f3tWq9GuKTnvTJz2onOqqi5FsQm/8c1dy2lh5DI1a8z6ICcmN 1FU21dWi7iOSBhKY8BzIGoT34G+iYATh8pPo98jasxwf5jfnhwemw9/3E= 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:to:cc :from:subject:message-id:date:mime-version:content-type; s= default; bh=36IAm/AA6JeLzRzCJEpOClRJBv0=; b=jePzGiBufjGfkgI6LxHC TRZmGdcvIZH6Ub7KOezhbItWwqYWvR2aXfpLNqKvlHboF1i5L131FrZDwB6UYcWB Yk70hj8q+DA/x9/ut1OhN2UmpDQfg+t1LaLoW4jeQhd8SihZZ0gLiKbw+E9hA/bb NkaGQ+uWWgBUNJmifueQD1g= Received: (qmail 55164 invoked by alias); 23 Apr 2018 21:17:34 -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 54828 invoked by uid 89); 23 Apr 2018 21:17:33 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-11.1 required=5.0 tests=BAYES_00, GIT_PATCH_2, GIT_PATCH_3, KAM_ASCII_DIVIDERS, RCVD_IN_DNSWL_NONE, SPF_HELO_PASS, SPF_PASS autolearn=ham version=3.3.2 spammy=Hx-languages-length:1899, locals X-HELO: aserp2120.oracle.com Received: from aserp2120.oracle.com (HELO aserp2120.oracle.com) (141.146.126.78) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 23 Apr 2018 21:17:32 +0000 Received: from pps.filterd (aserp2120.oracle.com [127.0.0.1]) by aserp2120.oracle.com (8.16.0.22/8.16.0.22) with SMTP id w3NLGecj189616; Mon, 23 Apr 2018 21:17:30 GMT Received: from userv0022.oracle.com (userv0022.oracle.com [156.151.31.74]) by aserp2120.oracle.com with ESMTP id 2hfw9a79kj-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 23 Apr 2018 21:17:30 +0000 Received: from aserv0122.oracle.com (aserv0122.oracle.com [141.146.126.236]) by userv0022.oracle.com (8.14.4/8.14.4) with ESMTP id w3NLHT9U023114 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 23 Apr 2018 21:17:29 GMT Received: from abhmp0012.oracle.com (abhmp0012.oracle.com [141.146.116.18]) by aserv0122.oracle.com (8.14.4/8.14.4) with ESMTP id w3NLHS66024384; Mon, 23 Apr 2018 21:17:28 GMT Received: from [192.168.1.4] (/62.211.207.61) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Mon, 23 Apr 2018 14:17:27 -0700 To: "gcc-patches@gcc.gnu.org" Cc: Jason Merrill From: Paolo Carlini Subject: [C++ Patch] PR 68374 ("G++ -Wshadow doesn't warn about static member shadowing") Message-ID: <7e3c9162-07af-320d-c910-efaf65d86883@oracle.com> Date: Mon, 23 Apr 2018 23:17:23 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.7.0 MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=8872 signatures=668698 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 mlxscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1711220000 definitions=main-1804230212 X-IsSubscribed: yes Hi, this issue is by and large fixed in trunk, thus I wanted to resolve it as such, marking it as fixed for 8.1.0. However the text of the warning is misleading / wrong:     declaration of ‘mVar’ shadows a previous local where in fact the shadowed declaration isn't local, is a static data member of the class. It seems to me that we should simply not handle such static old decls in the conditional block handling locals shadowing other locals, thus handle those below, together with other non-static member declarations. Tested x86-64-linux. Thanks, Paolo. /////////////////// /cp 2018-04-23 Paolo Carlini PR c++/68374 * name-lookup.c (check_local_shadow): Don't handle static old declarations in the block handling locals shadowing locals. /testsuite 2018-04-23 Paolo Carlini PR c++/68374 * g++.dg/warn/Wshadow-13.C: New. Index: cp/name-lookup.c =================================================================== --- cp/name-lookup.c (revision 259571) +++ cp/name-lookup.c (working copy) @@ -2638,6 +2638,7 @@ check_local_shadow (tree decl) || (TREE_CODE (old) == TYPE_DECL && (!DECL_ARTIFICIAL (old) || TREE_CODE (decl) == TYPE_DECL))) + && !TREE_STATIC (old) && (!DECL_ARTIFICIAL (decl) || DECL_IMPLICIT_TYPEDEF_P (decl) || (VAR_P (decl) && DECL_ANON_UNION_VAR_P (decl)))) Index: testsuite/g++.dg/warn/Wshadow-13.C =================================================================== --- testsuite/g++.dg/warn/Wshadow-13.C (nonexistent) +++ testsuite/g++.dg/warn/Wshadow-13.C (working copy) @@ -0,0 +1,8 @@ +// PR c++/68374 +// { dg-options "-Wshadow" } + +class f { + static int mVar; // { dg-message "shadowed declaration" } + int g(int x) { int mVar=3; return x+mVar; } // { dg-warning "shadows a member of 'f'" } +}; +int f::mVar = 1;