PATCH: PR 13129
Mark Mitchell
mark@codesourcery.com
Mon Mar 22 18:07:00 GMT 2004
This patch fixes PR 13129 on the 3.4 branch, avoiding some spurious
Wshadow warnings due to the intermediate state of the c-decl.c rewrite
on the 3.4 branch.
I did not apply this patch to the mainline because Zack is fixing the
bug in a different way there. I also did not apply the test case to
the mainline because Zack may well already have another test case. If
not, Zack, please feel free to use this one. :-)
Tested on i686-pc-linux-gnu, applied on the 3.4 branch.
--
Mark Mitchell
CodeSourcery, LLC
mark@codesourcery.com
2004-03-21 Mark Mitchell <mark@codesourcery.com>
PR c/13129
* c-decl.c (warn_if_shadowing): Don't warn about a new declaration
of a file-scope entity.
2004-03-22 Mark Mitchell <mark@codesourcery.com>
PR c/13129
* gcc.dg/Wshadow-2.c: New test.
Index: c-decl.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/c-decl.c,v
retrieving revision 1.470.4.11
diff -c -5 -p -r1.470.4.11 c-decl.c
*** c-decl.c 18 Mar 2004 18:29:31 -0000 1.470.4.11
--- c-decl.c 22 Mar 2004 16:11:21 -0000
*************** warn_if_shadowing (tree x, tree old)
*** 1570,1580 ****
/* Don't warn about the parm names in function declarator
within a function declarator.
It would be nice to avoid warning in any function
declarator in a declaration, as opposed to a definition,
but there is no way to tell it's not a definition. */
! || (TREE_CODE (x) == PARM_DECL && current_scope->outer->parm_flag))
return;
if (TREE_CODE (old) == PARM_DECL)
warning ("%Jdeclaration of '%D' shadows a parameter", x, x);
else if (DECL_FILE_SCOPE_P (old))
--- 1570,1582 ----
/* Don't warn about the parm names in function declarator
within a function declarator.
It would be nice to avoid warning in any function
declarator in a declaration, as opposed to a definition,
but there is no way to tell it's not a definition. */
! || (TREE_CODE (x) == PARM_DECL && current_scope->outer->parm_flag)
! /* Shadow warnings only apply to local variables and parameters. */
! || (TREE_CODE (x) != PARM_DECL && DECL_FILE_SCOPE_P (x)))
return;
if (TREE_CODE (old) == PARM_DECL)
warning ("%Jdeclaration of '%D' shadows a parameter", x, x);
else if (DECL_FILE_SCOPE_P (old))
Index: testsuite/gcc.dg/Wshadow-2.c
===================================================================
RCS file: testsuite/gcc.dg/Wshadow-2.c
diff -N testsuite/gcc.dg/Wshadow-2.c
*** /dev/null 1 Jan 1970 00:00:00 -0000
--- testsuite/gcc.dg/Wshadow-2.c 22 Mar 2004 17:13:53 -0000
***************
*** 0 ****
--- 1,8 ----
+ /* PR 13129 */
+ /* { dg-options "-Wshadow" } */
+
+ extern struct foo bar;
+ void dummy()
+ {
+ extern struct foo bar;
+ }
More information about the Gcc-patches
mailing list