This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c/78359] Redeclaration of global variables is not reported
- From: "egall at gwmail dot gwu.edu" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Tue, 15 Nov 2016 13:49:28 +0000
- Subject: [Bug c/78359] Redeclaration of global variables is not reported
- Auto-submitted: auto-generated
- References: <bug-78359-4@http.gcc.gnu.org/bugzilla/>
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;
^~~~~~~