Nico Weber | 98dd085 | 2019-03-14 14:18:56 +0000 | [diff] [blame^] | 1 | // RUN: %clang_cc1 -fsyntax-only -verify -Wno-objc-root-class %s |
| 2 | // RUN: %clang_cc1 -std=c++98 -fsyntax-only -verify -Wno-objc-root-class %s |
| 3 | |
| 4 | #if !__has_feature(objc_c_static_assert) |
| 5 | #error failed |
| 6 | #endif |
| 7 | |
| 8 | #if __cplusplus >= 201103L |
| 9 | |
| 10 | #if !__has_feature(objc_cxx_static_assert) |
| 11 | #error failed |
| 12 | #endif |
| 13 | |
| 14 | // C++11 |
| 15 | |
| 16 | @interface A { |
| 17 | int a; |
| 18 | static_assert(1, ""); |
| 19 | _Static_assert(1, ""); |
| 20 | |
| 21 | static_assert(0, ""); // expected-error {{static_assert failed}} |
| 22 | _Static_assert(0, ""); // expected-error {{static_assert failed}} |
| 23 | |
| 24 | static_assert(a, ""); // expected-error {{static_assert expression is not an integral constant expression}} |
| 25 | static_assert(sizeof(a) == 4, ""); |
| 26 | static_assert(sizeof(a) == 3, ""); // expected-error {{static_assert failed}} |
| 27 | } |
| 28 | |
| 29 | static_assert(1, ""); |
| 30 | _Static_assert(1, ""); |
| 31 | |
| 32 | - (void)f; |
| 33 | @end |
| 34 | |
| 35 | @implementation A { |
| 36 | int b; |
| 37 | static_assert(1, ""); |
| 38 | _Static_assert(1, ""); |
| 39 | static_assert(sizeof(b) == 4, ""); |
| 40 | static_assert(sizeof(b) == 3, ""); // expected-error {{static_assert failed}} |
| 41 | } |
| 42 | |
| 43 | static_assert(1, ""); |
| 44 | |
| 45 | - (void)f { |
| 46 | static_assert(1, ""); |
| 47 | } |
| 48 | @end |
| 49 | |
| 50 | @interface B |
| 51 | @end |
| 52 | |
| 53 | @interface B () { |
| 54 | int b; |
| 55 | static_assert(sizeof(b) == 4, ""); |
| 56 | static_assert(sizeof(b) == 3, ""); // expected-error {{static_assert failed}} |
| 57 | } |
| 58 | @end |
| 59 | |
| 60 | #else |
| 61 | |
| 62 | #if __has_feature(objc_cxx_static_assert) |
| 63 | #error failed |
| 64 | #endif |
| 65 | |
| 66 | // C++98 |
| 67 | @interface A { |
| 68 | int a; |
| 69 | static_assert(1, ""); // expected-error {{type name requires a specifier or qualifier}} expected-error{{expected parameter declarator}} expected-error {{expected ')'}} expected-note {{to match this '('}} |
| 70 | _Static_assert(1, ""); |
| 71 | _Static_assert(0, ""); // expected-error {{static_assert failed}} |
| 72 | } |
| 73 | @end |
| 74 | #endif |