1 /* Tests for the "Initializer entry defined twice" warning. */
2 
3 /* Initializing a struct field twice should trigger the warning. */
4 struct normal {
5 	int field1;
6 	int field2;
7 };
8 
9 static struct normal struct_error = {
10 	.field1 = 0,
11 	.field1 = 0
12 };
13 
14 /* Initializing two different fields of a union should trigger the warning. */
15 struct has_union {
16 	int x;
17 	union {
18 		int a;
19 		int b;
20 	} y;
21 	int z;
22 };
23 
24 static struct has_union union_error = {
25 	.y = {
26 		.a = 0,
27 		.b = 0
28 	}
29 };
30 
31 /* Empty structures can make two fields have the same offset in a struct.
32  * Initializing both should not trigger the warning. */
33 struct empty { };
34 
35 struct same_offset {
36 	struct empty field1;
37 	int field2;
38 };
39 
40 static struct same_offset not_an_error = {
41 	.field1 = { },
42 	.field2 = 0
43 };
44 
45 /*
46  * _Bools generally take a whole byte, so ensure that we can initialize
47  * them without spewing a warning.
48  */
49 static _Bool boolarray[3] = {
50 	[0] = 1,
51 	[1] = 1,
52 };
53 
54 /*
55  * check-name: Initializer entry defined twice
56  *
57  * check-error-start
58 initializer-entry-defined-twice.c:10:10: warning: Initializer entry defined twice
59 initializer-entry-defined-twice.c:11:10:   also defined here
60 initializer-entry-defined-twice.c:26:18: warning: Initializer entry defined twice
61 initializer-entry-defined-twice.c:27:18:   also defined here
62  * check-error-end
63  */
64