From patchwork Thu Aug 25 02:32:52 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alan Modra X-Patchwork-Id: 111440 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 209CAB6F64 for ; Thu, 25 Aug 2011 12:33:19 +1000 (EST) Received: (qmail 5328 invoked by alias); 25 Aug 2011 02:33:17 -0000 Received: (qmail 5318 invoked by uid 22791); 25 Aug 2011 02:33:16 -0000 X-SWARE-Spam-Status: No, hits=-1.8 required=5.0 tests=AWL, BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, KAM_STOCKGEN, RCVD_IN_DNSWL_LOW, T_TO_NO_BRKTS_FREEMAIL X-Spam-Check-By: sourceware.org Received: from mail-gw0-f47.google.com (HELO mail-gw0-f47.google.com) (74.125.83.47) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Thu, 25 Aug 2011 02:33:00 +0000 Received: by gwb11 with SMTP id 11so1426102gwb.20 for ; Wed, 24 Aug 2011 19:32:59 -0700 (PDT) Received: by 10.150.201.17 with SMTP id y17mr218377ybf.248.1314239579390; Wed, 24 Aug 2011 19:32:59 -0700 (PDT) Received: from bubble.grove.modra.org ([115.187.252.19]) by mx.google.com with ESMTPS id p1sm827780yba.17.2011.08.24.19.32.57 (version=TLSv1/SSLv3 cipher=OTHER); Wed, 24 Aug 2011 19:32:58 -0700 (PDT) Received: by bubble.grove.modra.org (Postfix, from userid 1000) id 4C5DB170C2BC; Thu, 25 Aug 2011 12:02:52 +0930 (CST) Date: Thu, 25 Aug 2011 12:02:52 +0930 From: Alan Modra To: gcc-patches@gcc.gnu.org Subject: -Wshadow warning Message-ID: <20110825023252.GJ18554@bubble.grove.modra.org> Mail-Followup-To: gcc-patches@gcc.gnu.org MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.20 (2009-06-14) X-IsSubscribed: yes 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 Wouldn't -Wshadow be more useful if it obeyed -Wno-system-headers? For code like #include int foo (int atof); int foo (int atof) { return atof; } we currently do not warn on the prototype, but do on the function definition, leading to reports such as http://sourceware.org/bugzilla/show_bug.cgi?id=13121 The following has been bootstrapped and regression tested powerpc-linux. OK to apply? * c-decl.c (warn_if_shadowing): Don't warn if shadowed identifier is from system header. Index: gcc/c-decl.c =================================================================== --- gcc/c-decl.c (revision 178035) +++ gcc/c-decl.c (working copy) @@ -2516,7 +2516,10 @@ warn_if_shadowing (tree new_decl) /* Is anything being shadowed? Invisible decls do not count. */ for (b = I_SYMBOL_BINDING (DECL_NAME (new_decl)); b; b = b->shadowed) - if (b->decl && b->decl != new_decl && !b->invisible) + if (b->decl && b->decl != new_decl && !b->invisible + && (b->decl == error_mark_node + || diagnostic_report_warnings_p (global_dc, + DECL_SOURCE_LOCATION (b->decl)))) { tree old_decl = b->decl;