1 _Static_assert(1, "global ok"); 2 3 struct foo { 4 _Static_assert(1, "struct ok"); 5 }; 6 7 void bar(void) 8 { 9 _Static_assert(1, " func1 ok"); 10 int i; 11 i = 0; 12 _Static_assert(1, " func2 ok"); 13 14 if (1) { 15 _Static_assert(1, " func3 ok"); 16 } 17 } 18 19 _Static_assert(0, "expected assertion failure"); 20 21 static int f; 22 _Static_assert(f, "non-constant expression"); 23 24 static int *p; 25 _Static_assert(p, "non-integer expression"); 26 27 _Static_assert(0.1, "float expression"); 28 29 _Static_assert(!0 == 1, "non-trivial expression"); 30 31 static char array[4]; 32 _Static_assert(sizeof(array) == 4, "sizeof expression"); 33 34 static const char non_literal_string[] = "non literal string"; 35 _Static_assert(0, non_literal_string); 36 37 _Static_assert(1 / 0, "invalid expression: should not show up?"); 38 39 struct s { 40 char arr[16]; 41 _Static_assert(1, "inside struct"); 42 }; 43 44 union u { 45 char c; 46 int i; 47 _Static_assert(1, "inside union"); 48 }; 49 50 _Static_assert(sizeof(struct s) == 16, "sizeof assertion"); 51 52 _Static_assert(1, ); 53 _Static_assert(, ""); 54 _Static_assert(,); 55 56 /* 57 * check-name: static assertion 58 * 59 * check-error-start 60 static_assert.c:19:16: error: static assertion failed: "expected assertion failure" 61 static_assert.c:22:16: error: bad constant expression 62 static_assert.c:25:16: error: bad constant expression 63 static_assert.c:27:16: error: bad constant expression 64 static_assert.c:35:19: error: bad or missing string literal 65 static_assert.c:37:18: error: bad constant expression 66 static_assert.c:52:19: error: bad or missing string literal 67 static_assert.c:53:16: error: Expected constant expression 68 static_assert.c:54:16: error: Expected constant expression 69 static_assert.c:54:17: error: bad or missing string literal 70 * check-error-end 71 */