xref: /minix3/external/bsd/llvm/dist/clang/test/Sema/missing-field-initializers.c (revision f4a2713ac843a11c696ec80c0a5e3e5d80b4d338)
1*f4a2713aSLionel Sambuc // RUN: %clang_cc1 -fsyntax-only -verify -Wmissing-field-initializers %s
2*f4a2713aSLionel Sambuc 
3*f4a2713aSLionel Sambuc // This was PR4808.
4*f4a2713aSLionel Sambuc 
5*f4a2713aSLionel Sambuc struct Foo { int a, b; };
6*f4a2713aSLionel Sambuc 
7*f4a2713aSLionel Sambuc struct Foo foo0 = { 1 }; // expected-warning {{missing field 'b' initializer}}
8*f4a2713aSLionel Sambuc struct Foo foo1 = { .a = 1 }; // designator avoids MFI warning
9*f4a2713aSLionel Sambuc struct Foo foo2 = { .b = 1 }; // designator avoids MFI warning
10*f4a2713aSLionel Sambuc 
11*f4a2713aSLionel Sambuc struct Foo bar0[] = {
12*f4a2713aSLionel Sambuc   { 1,2 },
13*f4a2713aSLionel Sambuc   { 1 },   // expected-warning {{missing field 'b' initializer}}
14*f4a2713aSLionel Sambuc   { 1,2 }
15*f4a2713aSLionel Sambuc };
16*f4a2713aSLionel Sambuc 
17*f4a2713aSLionel Sambuc struct Foo bar1[] = {
18*f4a2713aSLionel Sambuc   1, 2,
19*f4a2713aSLionel Sambuc   1, 2,
20*f4a2713aSLionel Sambuc   1
21*f4a2713aSLionel Sambuc }; // expected-warning {{missing field 'b' initializer}}
22*f4a2713aSLionel Sambuc 
23*f4a2713aSLionel Sambuc struct Foo bar2[] = { {}, {}, {} };
24*f4a2713aSLionel Sambuc 
25*f4a2713aSLionel Sambuc struct One { int a; int b; };
26*f4a2713aSLionel Sambuc struct Two { float c; float d; float e; };
27*f4a2713aSLionel Sambuc 
28*f4a2713aSLionel Sambuc struct Three {
29*f4a2713aSLionel Sambuc     union {
30*f4a2713aSLionel Sambuc         struct One one;
31*f4a2713aSLionel Sambuc         struct Two two;
32*f4a2713aSLionel Sambuc     } both;
33*f4a2713aSLionel Sambuc };
34*f4a2713aSLionel Sambuc 
35*f4a2713aSLionel Sambuc struct Three t0 = {
36*f4a2713aSLionel Sambuc     { .one = { 1, 2 } }
37*f4a2713aSLionel Sambuc };
38*f4a2713aSLionel Sambuc struct Three t1 = {
39*f4a2713aSLionel Sambuc     { .two = { 1.0f, 2.0f, 3.0f } }
40*f4a2713aSLionel Sambuc };
41*f4a2713aSLionel Sambuc 
42*f4a2713aSLionel Sambuc struct Three data[] = {
43*f4a2713aSLionel Sambuc   { { .one = { 1, 2 } } },
44*f4a2713aSLionel Sambuc   { { .one = { 1 } } }, // expected-warning {{missing field 'b' initializer}}
45*f4a2713aSLionel Sambuc   { { .two = { 1.0f, 2.0f, 3.0f } } },
46*f4a2713aSLionel Sambuc   { { .two = { 1.0f, 2.0f } } } // expected-warning {{missing field 'e' initializer}}
47*f4a2713aSLionel Sambuc };
48*f4a2713aSLionel Sambuc 
49*f4a2713aSLionel Sambuc struct { int:5; int a; int:5; int b; int:5; } noNamedImplicit[] = {
50*f4a2713aSLionel Sambuc   { 1, 2 },
51*f4a2713aSLionel Sambuc   { 1 } // expected-warning {{missing field 'b' initializer}}
52*f4a2713aSLionel Sambuc };
53