summaryrefslogtreecommitdiff
path: root/test/Sema
diff options
context:
space:
mode:
authorDaniel Marjamaki <daniel.marjamaki@evidente.se>2017-09-29 09:44:41 +0000
committerDaniel Marjamaki <daniel.marjamaki@evidente.se>2017-09-29 09:44:41 +0000
commit94efed908a60ba04964f220f0822e3463d0dcc38 (patch)
tree6390441a77ed87103534f67381b97a4173e57215 /test/Sema
parent2fb39644fd947db828c0d8ecf36edd2d387dac8c (diff)
downloadclang-94efed908a60ba04964f220f0822e3463d0dcc38.tar.gz
[Sema] Suppress warnings for C's zero initializer
Patch by S. Gilles! Differential Revision: https://reviews.llvm.org/D28148 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@314499 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'test/Sema')
-rw-r--r--test/Sema/zero-initializer.c38
1 files changed, 38 insertions, 0 deletions
diff --git a/test/Sema/zero-initializer.c b/test/Sema/zero-initializer.c
new file mode 100644
index 0000000000..472eed9517
--- /dev/null
+++ b/test/Sema/zero-initializer.c
@@ -0,0 +1,38 @@
+// 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; };
+
+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 }; // expected-warning {{suggest braces around initialization of subobject}} expected-warning {{suggest braces around initialization of subobject}}
+ 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 }; // expected-warning {{suggest braces around initialization of subobject}} expected-warning {{suggest braces around initialization of subobject}}
+
+ return 0;
+}