Nico Weber | 98dd085 | 2019-03-14 14:18:56 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 -fobjc-runtime=macosx-fragile -fsyntax-only -verify -Wno-objc-root-class %s |
| 2 | // RUN: %clang_cc1 -std=c89 -fobjc-runtime=macosx-fragile -fsyntax-only -verify -Wno-objc-root-class %s |
| 3 | |
| 4 | |
| 5 | #if __STDC_VERSION__ >= 201112L |
| 6 | |
| 7 | #if !__has_feature(objc_c_static_assert) |
| 8 | #error failed |
| 9 | #endif |
| 10 | |
| 11 | #if !__has_extension(objc_c_static_assert) |
| 12 | #error failed |
| 13 | #endif |
| 14 | |
| 15 | @interface A { |
| 16 | int a; |
| 17 | _Static_assert(1, ""); |
| 18 | _Static_assert(0, ""); // expected-error {{static_assert failed}} |
| 19 | |
| 20 | _Static_assert(a, ""); // expected-error {{use of undeclared identifier 'a'}} |
| 21 | _Static_assert(sizeof(a), ""); // expected-error {{use of undeclared identifier 'a'}} |
| 22 | } |
| 23 | |
| 24 | _Static_assert(1, ""); |
| 25 | |
| 26 | @end |
| 27 | |
| 28 | struct S { |
| 29 | @defs(A); |
| 30 | }; |
| 31 | |
| 32 | #else |
| 33 | |
| 34 | // _Static_assert is available before C11 as an extension, but -pedantic |
| 35 | // warns on it. |
| 36 | #if __has_feature(objc_c_static_assert) |
| 37 | #error failed |
| 38 | #endif |
| 39 | |
| 40 | #if !__has_extension(objc_c_static_assert) |
| 41 | #error failed |
| 42 | #endif |
| 43 | |
| 44 | @interface A { |
| 45 | int a; |
| 46 | _Static_assert(1, ""); |
| 47 | _Static_assert(0, ""); // expected-error {{static_assert failed}} |
| 48 | } |
| 49 | |
| 50 | _Static_assert(1, ""); |
| 51 | |
| 52 | @end |
| 53 | |
| 54 | #endif |