[Bug c/76732] Improve Woverride-init

ro at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Thu Nov 30 15:37:00 GMT 2017


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
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

Seems gcc should really follow here.

More information about the Gcc-bugs mailing list