This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c/23228] [3.4/4.0/4.1 Regression] Silly "unused variable" warning after redeclaration of a local variable
- From: "steven at gcc dot gnu dot org" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 12 Oct 2005 19:37:20 -0000
- Subject: [Bug c/23228] [3.4/4.0/4.1 Regression] Silly "unused variable" warning after redeclaration of a local variable
- References: <bug-23228-280@http.gcc.gnu.org/bugzilla/>
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
------- Comment #4 from steven at gcc dot gnu dot org 2005-10-12 19:37 -------
What about this....
Index: c-decl.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/c-decl.c,v
retrieving revision 1.687
diff -u -3 -p -r1.687 c-decl.c
--- c-decl.c 4 Oct 2005 13:58:41 -0000 1.687
+++ c-decl.c 12 Oct 2005 19:33:17 -0000
@@ -803,6 +803,7 @@ pop_scope (void)
case VAR_DECL:
/* Warnings for unused variables. */
if (!TREE_USED (p)
+ && !TREE_NO_WARNING (p)
&& !DECL_IN_SYSTEM_HEADER (p)
&& DECL_NAME (p)
&& !DECL_ARTIFICIAL (p)
@@ -1876,7 +1877,11 @@ duplicate_decls (tree newdecl, tree oldd
tree newtype = NULL, oldtype = NULL;
if (!diagnose_mismatched_decls (newdecl, olddecl, &newtype, &oldtype))
- return false;
+ {
+ /* Avoid `unused variable' and other warnings warnings for OLDDECL. */
+ TREE_NO_WARNING (olddecl) = 1;
+ return false;
+ }
merge_decls (newdecl, olddecl, newtype, oldtype);
return true;
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=23228