Incorrect missing initializer warning in anonymous structure in union
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-
.api_
^
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_
.api_
.code_
.code_
};
Changed in gcc-arm-embedded: | |
status: | New → Fix Released |
Hi Kristine,
What gcc version are you using?
Thanks,
Tejas.