Incorrect missing initializer warning in anonymous structure in union

Bug #1573865 reported by Kristine
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
GNU Arm Embedded Toolchain
Fix Released
Undecided
Unassigned

Bug Description

GCC incorrectly reports structure elements as uninitialized when -Wextra is used. This appears to be specific to anonymous structures in unions.

You can easily reproduce this by creating a file called test.c (see contents below) and compiling with this command:
arm-none-eabi-gcc -mcpu=cortex-m4 -mthumb -Wextra -std=c99 -c -o "test.o" -x c "test.c"

When test.c is compiled, I get this warning even though api_version_major is clearly initialized:
test.c:18:5: warning: missing initializer for field 'api_version_major' of 'struct <anonymous>' [-Wmissing-field-initializers]
     .api_version_major = 1,
     ^
test.c:11:17: note: 'api_version_major' declared here
         uint8_t api_version_major;

File contents of test.c:

#include <stdint.h>

typedef union st_version
{
    uint32_t version_id;
    struct
    {
        uint8_t code_version_minor;
        uint8_t code_version_major;
        uint8_t api_version_minor;
        uint8_t api_version_major;
    };
} version_t;

static const version_t version =
{
    .api_version_minor = 1,
    .api_version_major = 1,
    .code_version_major = 1,
    .code_version_minor = 0
};

Revision history for this message
Tejas Belagod (belagod-tejas) wrote :

Hi Kristine,

What gcc version are you using?

Thanks,
Tejas.

Revision history for this message
Kristine (kjassman) wrote :

Hi Tejas,

I was using 4.9 2015q3. Sorry, I should have tested the latest version before reporting. I just tried version 5.3 2016q1 and this is fixed. You can close this.

Thanks,
Kristine

Changed in gcc-arm-embedded:
status: New → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.