This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c/76732] Improve Woverride-init
- From: "ro at gcc dot gnu.org" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Thu, 30 Nov 2017 15:37:08 +0000
- Subject: [Bug c/76732] Improve Woverride-init
- Auto-submitted: auto-generated
- References: <bug-76732-4@http.gcc.gnu.org/bugzilla/>
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=76732
Rainer Orth <ro at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |ro at gcc dot gnu.org
--- Comment #8 from Rainer Orth <ro at gcc dot gnu.org> ---
Created attachment 42755
--> https://gcc.gnu.org/bugzilla/attachment.cgi?id=42755&action=edit
different testcase
I've been pointed at the attached testcase.
With Oracle Studio cc, I get
ptr_a = hello
ptr_b = (null)
ptr_c = goodbye
while both gcc and clang produce
ptr_a = (null)
ptr_b = (null)
ptr_c = goodbye
It seems Studio cc is wrong according to C11 6.7.9 par. 19. However clang
warns
by default
union.c:40:3: warning: initializer overrides prior initialization of this
subobject [-Winitializer-overrides]
.ptr_c = "goodbye"
^~~~~
union.c:36:21: note: expanded from macro 'ptr_c'
#define ptr_c ops_u.ops_v2.v2_c
~^~~~~~
union.c:39:3: note: previous initialization is here
.ptr_a = "hello",
^~~~~~~~~~~~~~~
union.c:34:27: note: expanded from macro 'ptr_a'
#define ptr_a ops_u.ops_v1.v1_a
^
1 warning generated.
even withou any additional options, which gcc 8.0.0 doesn't even with -Wall
-Woverride-init.
Seems gcc should really follow here.