1 // RUN: %clang_cc1 -std=c99 -Wmissing-field-initializers -Wmissing-braces -verify %s 2 3 // Tests that using {0} in struct initialization or assignment is supported 4 struct foo { int x; int y; }; 5 struct bar { struct foo a; struct foo b; }; 6 struct A { int a; }; 7 struct B { struct A a; }; 8 struct C { struct B b; }; 9 struct D { struct C c; int n; }; 10 11 int main(void) 12 { 13 struct foo f = { 0 }; // no-warning 14 struct foo g = { 9 }; // expected-warning {{missing field 'y' initializer}} 15 struct foo h = { 9, 9 }; // no-warning 16 struct bar i = { 0 }; // no-warning 17 struct bar j = { 0, 0 }; // expected-warning {{suggest braces around initialization of subobject}} expected-warning {{missing field 'b' initializer}} 18 struct bar k = { { 9, 9 }, { 9, 9 } }; // no-warning 19 struct bar l = { { 9, 9 }, { 0 } }; // no-warning 20 struct bar m = { { 0 }, { 0 } }; // no-warning 21 struct bar n = { { 0 }, { 9, 9 } }; // no-warning 22 struct bar o = { { 9 }, { 9, 9 } }; // expected-warning {{missing field 'y' initializer}} 23 struct C p = { 0 }; // no-warning 24 struct C q = { 9 }; // warning suppressed for struct with single element 25 struct D r = { 9 }; // expected-warning {{suggest braces around initialization of subobject}} expected-warning {{missing field 'n' initializer}} 26 f = (struct foo ) { 0 }; // no-warning 27 g = (struct foo ) { 9 }; // expected-warning {{missing field 'y' initializer}} 28 h = (struct foo ) { 9, 9 }; // no-warning 29 i = (struct bar) { 0 }; // no-warning 30 j = (struct bar) { 0, 0 }; // expected-warning {{suggest braces around initialization of subobject}} expected-warning {{missing field 'b' initializer}} 31 k = (struct bar) { { 9, 9 }, { 9, 9 } }; // no-warning 32 l = (struct bar) { { 9, 9 }, { 0 } }; // no-warning 33 m = (struct bar) { { 0 }, { 0 } }; // no-warning 34 n = (struct bar) { { 0 }, { 9, 9 } }; // no-warning 35 o = (struct bar) { { 9 }, { 9, 9 } }; // expected-warning {{missing field 'y' initializer}} 36 p = (struct C) { 0 }; // no-warning 37 q = (struct C) { 9 }; // warning suppressed for struct with single element 38 r = (struct D) { 9 }; // expected-warning {{suggest braces around initialization of subobject}} expected-warning {{missing field 'n' initializer}} 39 40 return 0; 41 } 42