Add PR check to suggest alternatives to using undef (#118506)
[llvm-project.git] / clang / test / Parser / objc-static-assert.mm
blob12ee2f978b2dfae7aff290694ac57c497073e23e
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
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
11 #if __cplusplus >= 201103L
13 #if !__has_feature(objc_cxx_static_assert)
14 #error failed
15 #endif
17 // C++11
19 @interface A {
20   int a;
21   static_assert(1, "");
22   _Static_assert(1, "");
24   static_assert(0, ""); // expected-error {{static assertion failed}}
25   _Static_assert(0, ""); // expected-error {{static assertion failed}}
27   static_assert(a, ""); // expected-error {{static assertion expression is not an integral constant expression}}
28   static_assert(sizeof(a) == 4, "");
29   static_assert(sizeof(a) == 3, ""); // expected-error {{static assertion failed}} \
30                                      // expected-note {{evaluates to '4 == 3'}}
33 static_assert(1, "");
34 _Static_assert(1, "");
36 - (void)f;
37 @end
39 @implementation A {
40   int b;
41   static_assert(1, "");
42   _Static_assert(1, "");
43   static_assert(sizeof(b) == 4, "");
44   static_assert(sizeof(b) == 3, ""); // expected-error {{static assertion failed}} \
45                                      // expected-note {{evaluates to '4 == 3'}}
48 static_assert(1, "");
50 - (void)f {
51   static_assert(1, "");
53 @end
55 @interface B
56 @end
58 @interface B () {
59   int b;
60   static_assert(sizeof(b) == 4, "");
61   static_assert(sizeof(b) == 3, ""); // expected-error {{static assertion failed}} \
62                                      // expected-note {{evaluates to '4 == 3'}}
64 @end
66 #else
68 #if __has_feature(objc_cxx_static_assert)
69 #error failed
70 #endif
72 // C++98
73 @interface A {
74   int a;
75   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 '('}}
76   _Static_assert(1, "");
77   _Static_assert(0, ""); // expected-error {{static assertion failed}}
79 @end
80 #endif