Hi,
I wonder if the following is a bug:
#include <stdio.h>
int main(void)
{
struct str {
struct a {
int a1, a2;
} a;
};
struct str src = {.a = {.a1 = 1, .a2 = 2}};
struct str dest = {.a = src.a, .a.a2 = 3};
printf("src: %u %u, dest: %u %u\n", src.a.a1, src.a.a2, dest.a.a1,
dest.a.a2);
return 0;
}
$ gcc -W -Wall test.c -o test
$ ./test
src: 1 2, dest: 0 3
GCC 4.8.4 (ARM), Red Hat 4.9.2-6, Red Hat 5.1.1-1 (x86-64 Fedora 21 and 22).
Should I file a bz report?
BTW changing the initializer from ".a = src.a" to ".a = {1, 2}" produces
the expected result:
$ gcc -W -Wall test.c -o test
test.c: In function ‘main’:
test.c:13:9: warning: initialized field overwritten [-Woverride-init]
struct str dest = {.a = {1, 2}, .a.a2 = 3};
^
test.c:13:9: warning: (near initialization for ‘dest.a.a2’) [-Woverride-init]
$ ./test
src: 1 2, dest: 1 3
--
Krzysztof Halasa
Industrial Research Institute for Automation and Measurements PIAP
Al. Jerozolimskie 202, 02-486 Warsaw, Poland