180639debfb2d90b2f1ffdbcd9a391f744cb0a393John McCall// RUN: %clang_cc1 -fsyntax-only -verify -Wmissing-field-initializers %s
280639debfb2d90b2f1ffdbcd9a391f744cb0a393John McCall
3d7358a3a63e66aafc49f394613a3afe4403d7c6bJohn McCall// This was PR4808.
4d7358a3a63e66aafc49f394613a3afe4403d7c6bJohn McCall
580639debfb2d90b2f1ffdbcd9a391f744cb0a393John McCallstruct Foo { int a, b; };
680639debfb2d90b2f1ffdbcd9a391f744cb0a393John McCall
780639debfb2d90b2f1ffdbcd9a391f744cb0a393John McCallstruct Foo foo0 = { 1 }; // expected-warning {{missing field 'b' initializer}}
880639debfb2d90b2f1ffdbcd9a391f744cb0a393John McCallstruct Foo foo1 = { .a = 1 }; // designator avoids MFI warning
980639debfb2d90b2f1ffdbcd9a391f744cb0a393John McCallstruct Foo foo2 = { .b = 1 }; // designator avoids MFI warning
1080639debfb2d90b2f1ffdbcd9a391f744cb0a393John McCall
1180639debfb2d90b2f1ffdbcd9a391f744cb0a393John McCallstruct Foo bar0[] = {
1280639debfb2d90b2f1ffdbcd9a391f744cb0a393John McCall  { 1,2 },
1380639debfb2d90b2f1ffdbcd9a391f744cb0a393John McCall  { 1 },   // expected-warning {{missing field 'b' initializer}}
1480639debfb2d90b2f1ffdbcd9a391f744cb0a393John McCall  { 1,2 }
1580639debfb2d90b2f1ffdbcd9a391f744cb0a393John McCall};
1680639debfb2d90b2f1ffdbcd9a391f744cb0a393John McCall
1780639debfb2d90b2f1ffdbcd9a391f744cb0a393John McCallstruct Foo bar1[] = {
1880639debfb2d90b2f1ffdbcd9a391f744cb0a393John McCall  1, 2,
1980639debfb2d90b2f1ffdbcd9a391f744cb0a393John McCall  1, 2,
2080639debfb2d90b2f1ffdbcd9a391f744cb0a393John McCall  1
2180639debfb2d90b2f1ffdbcd9a391f744cb0a393John McCall}; // expected-warning {{missing field 'b' initializer}}
2280639debfb2d90b2f1ffdbcd9a391f744cb0a393John McCall
238e19890c329279c5ac35ab71a35423d429d80165Douglas Gregorstruct Foo bar2[] = { {}, {}, {} };
248e19890c329279c5ac35ab71a35423d429d80165Douglas Gregor
2580639debfb2d90b2f1ffdbcd9a391f744cb0a393John McCallstruct One { int a; int b; };
2680639debfb2d90b2f1ffdbcd9a391f744cb0a393John McCallstruct Two { float c; float d; float e; };
2780639debfb2d90b2f1ffdbcd9a391f744cb0a393John McCall
2880639debfb2d90b2f1ffdbcd9a391f744cb0a393John McCallstruct Three {
2980639debfb2d90b2f1ffdbcd9a391f744cb0a393John McCall    union {
3080639debfb2d90b2f1ffdbcd9a391f744cb0a393John McCall        struct One one;
3180639debfb2d90b2f1ffdbcd9a391f744cb0a393John McCall        struct Two two;
3280639debfb2d90b2f1ffdbcd9a391f744cb0a393John McCall    } both;
3380639debfb2d90b2f1ffdbcd9a391f744cb0a393John McCall};
3480639debfb2d90b2f1ffdbcd9a391f744cb0a393John McCall
3580639debfb2d90b2f1ffdbcd9a391f744cb0a393John McCallstruct Three t0 = {
3680639debfb2d90b2f1ffdbcd9a391f744cb0a393John McCall    { .one = { 1, 2 } }
3780639debfb2d90b2f1ffdbcd9a391f744cb0a393John McCall};
3880639debfb2d90b2f1ffdbcd9a391f744cb0a393John McCallstruct Three t1 = {
3980639debfb2d90b2f1ffdbcd9a391f744cb0a393John McCall    { .two = { 1.0f, 2.0f, 3.0f } }
4080639debfb2d90b2f1ffdbcd9a391f744cb0a393John McCall};
4180639debfb2d90b2f1ffdbcd9a391f744cb0a393John McCall
4280639debfb2d90b2f1ffdbcd9a391f744cb0a393John McCallstruct Three data[] = {
4380639debfb2d90b2f1ffdbcd9a391f744cb0a393John McCall  { { .one = { 1, 2 } } },
4480639debfb2d90b2f1ffdbcd9a391f744cb0a393John McCall  { { .one = { 1 } } }, // expected-warning {{missing field 'b' initializer}}
4580639debfb2d90b2f1ffdbcd9a391f744cb0a393John McCall  { { .two = { 1.0f, 2.0f, 3.0f } } },
4680639debfb2d90b2f1ffdbcd9a391f744cb0a393John McCall  { { .two = { 1.0f, 2.0f } } } // expected-warning {{missing field 'e' initializer}}
4780639debfb2d90b2f1ffdbcd9a391f744cb0a393John McCall};
4880639debfb2d90b2f1ffdbcd9a391f744cb0a393John McCall
49e224ba7e3e604113aa160c379293bcb6425e8f36Carl Norumstruct { int:5; int a; int:5; int b; int:5; } noNamedImplicit[] = {
5080639debfb2d90b2f1ffdbcd9a391f744cb0a393John McCall  { 1, 2 },
5180639debfb2d90b2f1ffdbcd9a391f744cb0a393John McCall  { 1 } // expected-warning {{missing field 'b' initializer}}
5280639debfb2d90b2f1ffdbcd9a391f744cb0a393John McCall};
53