missing-field-initializers.c 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. // RUN: %clang_cc1 -fsyntax-only -verify -Wmissing-field-initializers %s
  2. // This was PR4808.
  3. struct Foo { int a, b; };
  4. struct Foo foo0 = { 1 }; // expected-warning {{missing field 'b' initializer}}
  5. struct Foo foo1 = { .a = 1 }; // designator avoids MFI warning
  6. struct Foo foo2 = { .b = 1 }; // designator avoids MFI warning
  7. struct Foo bar0[] = {
  8. { 1,2 },
  9. { 1 }, // expected-warning {{missing field 'b' initializer}}
  10. { 1,2 }
  11. };
  12. struct Foo bar1[] = {
  13. 1, 2,
  14. 1, 2,
  15. 1
  16. }; // expected-warning {{missing field 'b' initializer}}
  17. struct Foo bar2[] = { {}, {}, {} };
  18. struct One { int a; int b; };
  19. struct Two { float c; float d; float e; };
  20. struct Three {
  21. union {
  22. struct One one;
  23. struct Two two;
  24. } both;
  25. };
  26. struct Three t0 = {
  27. { .one = { 1, 2 } }
  28. };
  29. struct Three t1 = {
  30. { .two = { 1.0f, 2.0f, 3.0f } }
  31. };
  32. struct Three data[] = {
  33. { { .one = { 1, 2 } } },
  34. { { .one = { 1 } } }, // expected-warning {{missing field 'b' initializer}}
  35. { { .two = { 1.0f, 2.0f, 3.0f } } },
  36. { { .two = { 1.0f, 2.0f } } } // expected-warning {{missing field 'e' initializer}}
  37. };
  38. struct { int:5; int a; int:5; int b; int:5; } noNamedImplicit[] = {
  39. { 1, 2 },
  40. { 1 } // expected-warning {{missing field 'b' initializer}}
  41. };