John McCall | 80639de | 2010-03-11 19:32:38 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 -fsyntax-only -verify -Wmissing-field-initializers %s |
| 2 | |
John McCall | d7358a3 | 2010-03-11 19:33:57 +0000 | [diff] [blame] | 3 | // This was PR4808. |
| 4 | |
John McCall | 80639de | 2010-03-11 19:32:38 +0000 | [diff] [blame] | 5 | struct Foo { int a, b; }; |
| 6 | |
| 7 | struct Foo foo0 = { 1 }; // expected-warning {{missing field 'b' initializer}} |
| 8 | struct Foo foo1 = { .a = 1 }; // designator avoids MFI warning |
| 9 | struct Foo foo2 = { .b = 1 }; // designator avoids MFI warning |
| 10 | |
| 11 | struct Foo bar0[] = { |
| 12 | { 1,2 }, |
| 13 | { 1 }, // expected-warning {{missing field 'b' initializer}} |
| 14 | { 1,2 } |
| 15 | }; |
| 16 | |
| 17 | struct Foo bar1[] = { |
| 18 | 1, 2, |
| 19 | 1, 2, |
| 20 | 1 |
| 21 | }; // expected-warning {{missing field 'b' initializer}} |
| 22 | |
Douglas Gregor | 8e19890 | 2010-06-18 21:43:10 +0000 | [diff] [blame] | 23 | struct Foo bar2[] = { {}, {}, {} }; |
| 24 | |
John McCall | 80639de | 2010-03-11 19:32:38 +0000 | [diff] [blame] | 25 | struct One { int a; int b; }; |
| 26 | struct Two { float c; float d; float e; }; |
| 27 | |
| 28 | struct Three { |
| 29 | union { |
| 30 | struct One one; |
| 31 | struct Two two; |
| 32 | } both; |
| 33 | }; |
| 34 | |
| 35 | struct Three t0 = { |
| 36 | { .one = { 1, 2 } } |
| 37 | }; |
| 38 | struct Three t1 = { |
| 39 | { .two = { 1.0f, 2.0f, 3.0f } } |
| 40 | }; |
| 41 | |
| 42 | struct Three data[] = { |
| 43 | { { .one = { 1, 2 } } }, |
| 44 | { { .one = { 1 } } }, // expected-warning {{missing field 'b' initializer}} |
| 45 | { { .two = { 1.0f, 2.0f, 3.0f } } }, |
| 46 | { { .two = { 1.0f, 2.0f } } } // expected-warning {{missing field 'e' initializer}} |
| 47 | }; |
| 48 | |
Carl Norum | e224ba7 | 2011-03-07 22:57:45 +0000 | [diff] [blame] | 49 | struct { int:5; int a; int:5; int b; int:5; } noNamedImplicit[] = { |
John McCall | 80639de | 2010-03-11 19:32:38 +0000 | [diff] [blame] | 50 | { 1, 2 }, |
| 51 | { 1 } // expected-warning {{missing field 'b' initializer}} |
| 52 | }; |