1 // RUN: %clang_cc1 -std=c99 -Wmissing-field-initializers -Wmissing-braces -verify %s
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
; };
7 struct B
{ struct A a
; };
8 struct C
{ struct B b
; };
9 struct D
{ struct C c
; int n
; };
10 struct E
{ short e
; };
11 struct F
{ struct E e
; int n
; };
15 struct foo f
= { 0 }; // no-warning
16 struct foo g
= { 9 }; // expected-warning {{missing field 'y' initializer}}
17 struct foo h
= { 9, 9 }; // no-warning
18 struct bar i
= { 0 }; // no-warning
19 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-warning
21 struct bar l
= { { 9, 9 }, { 0 } }; // no-warning
22 struct bar m
= { { 0 }, { 0 } }; // no-warning
23 struct bar n
= { { 0 }, { 9, 9 } }; // no-warning
24 struct bar o
= { { 9 }, { 9, 9 } }; // expected-warning {{missing field 'y' initializer}}
25 struct C p
= { 0 }; // no-warning
26 struct C q
= { 9 }; // warning suppressed for struct with single element
27 struct D r
= { 9 }; // expected-warning {{suggest braces around initialization of subobject}} expected-warning {{missing field 'n' initializer}}
28 struct F s
= { 0 }; // no-warning
29 struct F t
= { 9 }; // expected-warning {{suggest braces around initialization of subobject}} expected-warning {{missing field 'n' initializer}}
31 f
= (struct foo
) { 0 }; // no-warning
32 g
= (struct foo
) { 9 }; // expected-warning {{missing field 'y' initializer}}
33 h
= (struct foo
) { 9, 9 }; // no-warning
34 i
= (struct bar
) { 0 }; // no-warning
35 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-warning
37 l
= (struct bar
) { { 9, 9 }, { 0 } }; // no-warning
38 m
= (struct bar
) { { 0 }, { 0 } }; // no-warning
39 n
= (struct bar
) { { 0 }, { 9, 9 } }; // no-warning
40 o
= (struct bar
) { { 9 }, { 9, 9 } }; // expected-warning {{missing field 'y' initializer}}
41 p
= (struct C
) { 0 }; // no-warning
42 q
= (struct C
) { 9 }; // warning suppressed for struct with single element
43 r
= (struct D
) { 9 }; // expected-warning {{suggest braces around initialization of subobject}} expected-warning {{missing field 'n' initializer}}
44 s
= (struct F
) { 0 }; // no-warning
45 t
= (struct F
) { 9 }; // expected-warning {{suggest braces around initialization of subobject}} expected-warning {{missing field 'n' initializer}}