1_Static_assert(1, "global ok"); 2 3struct foo { 4 _Static_assert(1, "struct ok"); 5}; 6 7void 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 21static int f; 22_Static_assert(f, "non-constant expression"); 23 24static 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 31static char array[4]; 32_Static_assert(sizeof(array) == 4, "sizeof expression"); 33 34static 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 39struct s { 40 char arr[16]; 41 _Static_assert(1, "inside struct"); 42}; 43 44union 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// C2x's version: without message 57_Static_assert(1); 58_Static_assert(0); 59 60/* 61 * check-name: static assertion 62 * 63 * check-error-start 64static_assert.c:19:16: error: static assertion failed: "expected assertion failure" 65static_assert.c:22:16: error: bad constant expression 66static_assert.c:25:16: error: bad constant expression 67static_assert.c:27:16: error: bad constant expression 68static_assert.c:35:19: error: string literal expected for _Static_assert() 69static_assert.c:37:18: error: bad constant expression 70static_assert.c:52:19: error: string literal expected for _Static_assert() 71static_assert.c:53:16: error: Expected constant expression 72static_assert.c:54:16: error: Expected constant expression 73static_assert.c:54:17: error: string literal expected for _Static_assert() 74static_assert.c:58:16: error: static assertion failed 75 * check-error-end 76 */ 77