Patchwork -Wshadow warning

login
register
mail settings
Submitter Alan Modra
Date Aug. 25, 2011, 2:32 a.m.
Message ID <20110825023252.GJ18554@bubble.grove.modra.org>
Download mbox | patch
Permalink /patch/111440/
State New
Headers show

Comments

Alan Modra - Aug. 25, 2011, 2:32 a.m.
Wouldn't -Wshadow be more useful if it obeyed -Wno-system-headers?
For code like

	#include <stdlib.h>
	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.
Gabriel Dos Reis - Aug. 25, 2011, 12:38 p.m.
On Wed, Aug 24, 2011 at 9:32 PM, Alan Modra <amodra@gmail.com> wrote:
> Wouldn't -Wshadow be more useful if it obeyed -Wno-system-headers?
> For code like
>
>        #include <stdlib.h>
>        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?

OK.

>
>        * 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;
>
>
> --
> Alan Modra
> Australia Development Lab, IBM
>

Patch

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;