1/* Tests for the "Initializer entry defined twice" warning. */ 2 3/* Initializing a struct field twice should trigger the warning. */ 4struct normal { 5 int field1; 6 int field2; 7}; 8 9static struct normal struct_error = { 10 .field1 = 0, 11 .field1 = 0 12}; 13 14/* Initializing two different fields of a union should trigger the warning. */ 15struct has_union { 16 int x; 17 union { 18 int a; 19 int b; 20 } y; 21 int z; 22}; 23 24static 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. */ 33struct empty { }; 34 35struct same_offset { 36 struct empty field1; 37 int field2; 38}; 39 40static 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 */ 49static _Bool boolarray[3] = { 50 [0] = 1, 51 [1] = 1, 52}; 53 54/* 55 * check-name: Initializer entry defined twice 56 * 57 * check-error-start 58initializer-entry-defined-twice.c:10:10: warning: Initializer entry defined twice 59initializer-entry-defined-twice.c:11:10: also defined here 60initializer-entry-defined-twice.c:26:18: warning: Initializer entry defined twice 61initializer-entry-defined-twice.c:27:18: also defined here 62 * check-error-end 63 */ 64