File: zero-initializer.c

package info (click to toggle)
llvm-toolchain-7 1%3A7.0.1-8
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 733,456 kB
  • sloc: cpp: 3,776,651; ansic: 633,271; asm: 350,301; python: 142,716; objc: 107,612; sh: 22,626; lisp: 11,056; perl: 7,999; pascal: 6,742; ml: 5,537; awk: 3,536; makefile: 2,557; cs: 2,027; xml: 841; ruby: 156
file content (41 lines) | stat: -rw-r--r-- 2,214 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
// RUN: %clang_cc1 -std=c99 -Wmissing-field-initializers -Wmissing-braces -verify %s

// Tests that using {0} in struct initialization or assignment is supported
struct foo { int x; int y; };
struct bar { struct foo a; struct foo b; };
struct A { int a; };
struct B { struct A a; };
struct C { struct B b; };
struct D { struct C c; int n; };

int main(void)
{
  struct foo f = { 0 }; // no-warning
  struct foo g = { 9 }; // expected-warning {{missing field 'y' initializer}}
  struct foo h = { 9, 9 }; // no-warning
  struct bar i = { 0 }; // no-warning
  struct bar j = { 0, 0 }; // expected-warning {{suggest braces around initialization of subobject}} expected-warning {{missing field 'b' initializer}}
  struct bar k = { { 9, 9 }, { 9, 9 } }; // no-warning
  struct bar l = { { 9, 9 }, { 0 } }; // no-warning
  struct bar m = { { 0 }, { 0 } }; // no-warning
  struct bar n = { { 0 }, { 9, 9 } }; // no-warning
  struct bar o = { { 9 }, { 9, 9 } }; // expected-warning {{missing field 'y' initializer}}
  struct C p = { 0 }; // no-warning
  struct C q = { 9 }; // warning suppressed for struct with single element
  struct D r = { 9 }; // expected-warning {{suggest braces around initialization of subobject}} expected-warning {{missing field 'n' initializer}}
  f = (struct foo ) { 0 }; // no-warning
  g = (struct foo ) { 9 }; // expected-warning {{missing field 'y' initializer}}
  h = (struct foo ) { 9, 9 }; // no-warning
  i = (struct bar) { 0 }; // no-warning
  j = (struct bar) { 0, 0 }; // expected-warning {{suggest braces around initialization of subobject}} expected-warning {{missing field 'b' initializer}}
  k = (struct bar) { { 9, 9 }, { 9, 9 } }; // no-warning
  l = (struct bar) { { 9, 9 }, { 0 } }; // no-warning
  m = (struct bar) { { 0 }, { 0 } }; // no-warning
  n = (struct bar) { { 0 }, { 9, 9 } }; // no-warning
  o = (struct bar) { { 9 }, { 9, 9 } }; // expected-warning {{missing field 'y' initializer}}
  p = (struct C) { 0 }; // no-warning
  q = (struct C) { 9 }; // warning suppressed for struct with single element
  r = (struct D) { 9 }; // expected-warning {{suggest braces around initialization of subobject}} expected-warning {{missing field 'n' initializer}}

  return 0;
}