49 lines · c
1// RUN: %clang_cc1 -std=c99 -Wmissing-field-initializers -Wmissing-braces -verify %s2 3// Tests that using {0} in struct initialization or assignment is supported4struct foo { int x; int y; };5struct bar { struct foo a; struct foo b; };6struct A { int a; };7struct B { struct A a; };8struct C { struct B b; };9struct D { struct C c; int n; };10struct E { short e; };11struct F { struct E e; int n; };12 13int main(void)14{15 struct foo f = { 0 }; // no-warning16 struct foo g = { 9 }; // expected-warning {{missing field 'y' initializer}}17 struct foo h = { 9, 9 }; // no-warning18 struct bar i = { 0 }; // no-warning19 struct bar j = { 0, 0 }; // expected-warning {{suggest braces around initialization of subobject}} expected-warning {{missing field 'b' initializer}}20 struct bar k = { { 9, 9 }, { 9, 9 } }; // no-warning21 struct bar l = { { 9, 9 }, { 0 } }; // no-warning22 struct bar m = { { 0 }, { 0 } }; // no-warning23 struct bar n = { { 0 }, { 9, 9 } }; // no-warning24 struct bar o = { { 9 }, { 9, 9 } }; // expected-warning {{missing field 'y' initializer}}25 struct C p = { 0 }; // no-warning26 struct C q = { 9 }; // warning suppressed for struct with single element27 struct D r = { 9 }; // expected-warning {{suggest braces around initialization of subobject}} expected-warning {{missing field 'n' initializer}}28 struct F s = { 0 }; // no-warning29 struct F t = { 9 }; // expected-warning {{suggest braces around initialization of subobject}} expected-warning {{missing field 'n' initializer}}30 31 f = (struct foo ) { 0 }; // no-warning32 g = (struct foo ) { 9 }; // expected-warning {{missing field 'y' initializer}}33 h = (struct foo ) { 9, 9 }; // no-warning34 i = (struct bar) { 0 }; // no-warning35 j = (struct bar) { 0, 0 }; // expected-warning {{suggest braces around initialization of subobject}} expected-warning {{missing field 'b' initializer}}36 k = (struct bar) { { 9, 9 }, { 9, 9 } }; // no-warning37 l = (struct bar) { { 9, 9 }, { 0 } }; // no-warning38 m = (struct bar) { { 0 }, { 0 } }; // no-warning39 n = (struct bar) { { 0 }, { 9, 9 } }; // no-warning40 o = (struct bar) { { 9 }, { 9, 9 } }; // expected-warning {{missing field 'y' initializer}}41 p = (struct C) { 0 }; // no-warning42 q = (struct C) { 9 }; // warning suppressed for struct with single element43 r = (struct D) { 9 }; // expected-warning {{suggest braces around initialization of subobject}} expected-warning {{missing field 'n' initializer}}44 s = (struct F) { 0 }; // no-warning45 t = (struct F) { 9 }; // expected-warning {{suggest braces around initialization of subobject}} expected-warning {{missing field 'n' initializer}}46 47 return 0;48}49