[Bug c/78359] Redeclaration of global variables is not reported
egall at gwmail dot gwu.edu
gcc-bugzilla@gcc.gnu.org
Tue Nov 15 13:58:00 GMT 2016
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=78359
Eric Gallager <egall at gwmail dot gwu.edu> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |egall at gwmail dot gwu.edu
--- Comment #6 from Eric Gallager <egall at gwmail dot gwu.edu> ---
(In reply to Andrew Pinski from comment #4)
> (In reply to hugo74 from comment #2)
> > It should not work that way. I checked it in other C compilers and each of
> > them reports an redefinition error in such case.
>
> Are you sure they were C compilers and not C++ compilers?
>
> C and C++ differ here.
Hence -Wc++-compat gets the warning desired:
$ /usr/local/bin/gcc -Wall -Wextra -pedantic -Wredundant-decls -Wc++-compat
-fno-common -c pr78359.c
pr78359.c:1:14: warning: duplicate declaration of ‘Counter’ is invalid in C++
[-Wc++-compat]
int Counter, Counter, Counter;
^~~~~~~
pr78359.c:1:5: note: previous declaration of ‘Counter’ was here
int Counter, Counter, Counter;
^~~~~~~
pr78359.c:1:23: warning: duplicate declaration of ‘Counter’ is invalid in C++
[-Wc++-compat]
int Counter, Counter, Counter;
^~~~~~~
pr78359.c:1:14: note: previous declaration of ‘Counter’ was here
int Counter, Counter, Counter;
^~~~~~~
More information about the Gcc-bugs
mailing list