hooks: add a warning to detect unimplemented hooks
[smatch.git] / validation / static_assert.c
blob0ab5844edef1d93aaa121b5f5d75d384c3d94eb3
1 _Static_assert(1, "global ok");
3 struct foo {
4 _Static_assert(1, "struct ok");
5 };
7 void bar(void)
9 _Static_assert(1, " func1 ok");
10 int i;
11 i = 0;
12 _Static_assert(1, " func2 ok");
14 if (1) {
15 _Static_assert(1, " func3 ok");
19 _Static_assert(0, "expected assertion failure");
21 static int f;
22 _Static_assert(f, "non-constant expression");
24 static int *p;
25 _Static_assert(p, "non-integer expression");
27 _Static_assert(0.1, "float expression");
29 _Static_assert(!0 == 1, "non-trivial expression");
31 static char array[4];
32 _Static_assert(sizeof(array) == 4, "sizeof expression");
34 static const char non_literal_string[] = "non literal string";
35 _Static_assert(0, non_literal_string);
37 _Static_assert(1 / 0, "invalid expression: should not show up?");
39 struct s {
40 char arr[16];
41 _Static_assert(1, "inside struct");
44 union u {
45 char c;
46 int i;
47 _Static_assert(1, "inside union");
50 _Static_assert(sizeof(struct s) == 16, "sizeof assertion");
52 _Static_assert(1, );
53 _Static_assert(, "");
54 _Static_assert(,);
56 // C2x's version: without message
57 _Static_assert(1);
58 _Static_assert(0);
61 * check-name: static assertion
63 * check-error-start
64 static_assert.c:19:16: error: static assertion failed: "expected assertion failure"
65 static_assert.c:22:16: error: bad constant expression
66 static_assert.c:25:16: error: bad constant expression
67 static_assert.c:27:16: error: bad constant expression
68 static_assert.c:35:19: error: string literal expected for _Static_assert()
69 static_assert.c:37:18: error: bad constant expression
70 static_assert.c:52:19: error: string literal expected for _Static_assert()
71 static_assert.c:53:16: error: Expected constant expression
72 static_assert.c:54:16: error: Expected constant expression
73 static_assert.c:54:17: error: string literal expected for _Static_assert()
74 static_assert.c:58:16: error: static assertion failed
75 * check-error-end