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