This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c/45977] "warning: 'i' initialized and declared 'extern'" is spurious
- From: "cascardo at holoscopio dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Mon, 9 May 2011 04:01:13 +0000
- Subject: [Bug c/45977] "warning: 'i' initialized and declared 'extern'" is spurious
- Auto-submitted: auto-generated
- References: <bug-45977-4@http.gcc.gnu.org/bugzilla/>
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=45977
Thadeu Lima de Souza Cascardo <cascardo at holoscopio dot com> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |cascardo at holoscopio dot
| |com
--- Comment #4 from Thadeu Lima de Souza Cascardo <cascardo at holoscopio dot com> 2011-05-09 03:49:25 UTC ---
What seemed really strange to me is that the warning would be emitted even when
the static declaration was inside #if 0/#endif pair, since the pre-processor
would have removed the code entirely.
And reading the warning also told me the problem was assigning a value in the
extern declaration.
So
extern int i = 3;
is not fine. While
static int i = 3;
extern int i;
is perfectly OK. That is, without any warning on/off flags, there is no
warning. Should there be such a warning as Joseph says? -Wall -Wextra emits no
warning for static int i; extern int i; case. In fact, there is
-Wredundant-decls, but it only works if there is no initialization in the
extern declaration.
I can turn off this warning using -w, but there is no particular flag for this
warning. Should one of the existing flags be used or a new one be created?
Better yet, should gcc not warn when this initialization happens in this
particular case, when the variable has already been declared as static?