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 | #if !__has_extension(objc_c_static_assert) |
8 | #error failed |
9 | #endif |
10 | |
11 | #if __cplusplus >= 201103L |
12 | |
13 | #if !__has_feature(objc_cxx_static_assert) |
14 | #error failed |
15 | #endif |
16 | |
17 | // C++11 |
18 | |
19 | @interface A { |
20 | int a; |
21 | static_assert(1, ""); |
22 | _Static_assert(1, ""); |
23 | |
24 | static_assert(0, ""); // expected-error {{static_assert failed}} |
25 | _Static_assert(0, ""); // expected-error {{static_assert failed}} |
26 | |
27 | static_assert(a, ""); // expected-error {{static_assert expression is not an integral constant expression}} |
28 | static_assert(sizeof(a) == 4, ""); |
29 | static_assert(sizeof(a) == 3, ""); // expected-error {{static_assert failed}} |
30 | } |
31 | |
32 | static_assert(1, ""); |
33 | _Static_assert(1, ""); |
34 | |
35 | - (void)f; |
36 | @end |
37 | |
38 | @implementation A { |
39 | int b; |
40 | static_assert(1, ""); |
41 | _Static_assert(1, ""); |
42 | static_assert(sizeof(b) == 4, ""); |
43 | static_assert(sizeof(b) == 3, ""); // expected-error {{static_assert failed}} |
44 | } |
45 | |
46 | static_assert(1, ""); |
47 | |
48 | - (void)f { |
49 | static_assert(1, ""); |
50 | } |
51 | @end |
52 | |
53 | @interface B |
54 | @end |
55 | |
56 | @interface B () { |
57 | int b; |
58 | static_assert(sizeof(b) == 4, ""); |
59 | static_assert(sizeof(b) == 3, ""); // expected-error {{static_assert failed}} |
60 | } |
61 | @end |
62 | |
63 | #else |
64 | |
65 | #if __has_feature(objc_cxx_static_assert) |
66 | #error failed |
67 | #endif |
68 | |
69 | // C++98 |
70 | @interface A { |
71 | int a; |
72 | 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 '('}} |
73 | _Static_assert(1, ""); |
74 | _Static_assert(0, ""); // expected-error {{static_assert failed}} |
75 | } |
76 | @end |
77 | #endif |
78 | |