1 // RUN: %clang_cc1 -std=c11 -fsyntax-only -verify %s
2 // RUN: %clang_cc1 -fms-compatibility -DMS -fsyntax-only -verify=expected,ms %s
3 // RUN: %clang_cc1 -std=c99 -pedantic -fsyntax-only -verify=expected,ext %s
4 // RUN: %clang_cc1 -xc++ -std=c++11 -pedantic -fsyntax-only -verify=expected,ext,cxx %s
6 _Static_assert("foo", "string is nonzero"); // ext-warning {{'_Static_assert' is a C11 extension}}
8 // expected-error@-2 {{static_assert expression is not an integral constant expression}}
11 _Static_assert(1, "1 is nonzero"); // ext-warning {{'_Static_assert' is a C11 extension}}
12 _Static_assert(0, "0 is nonzero"); // expected-error {{static_assert failed "0 is nonzero"}} \
13 // ext-warning {{'_Static_assert' is a C11 extension}}
16 static_assert(1, "1 is nonzero"); // ms-warning {{use of 'static_assert' without inclusion of <assert.h> is a Microsoft extension}}
20 _Static_assert(1, "1 is nonzero"); // ext-warning {{'_Static_assert' is a C11 extension}}
21 _Static_assert(0, "0 is nonzero"); // expected-error {{static_assert failed "0 is nonzero"}} \
22 // ext-warning {{'_Static_assert' is a C11 extension}}
24 static_assert(1, "1 is nonzero"); // ms-warning {{use of 'static_assert' without}}
28 _Static_assert(1, invalid
); // expected-error {{expected string literal for diagnostic message in static_assert}} \
29 // ext-warning {{'_Static_assert' is a C11 extension}}
33 _Static_assert(1, "1 is nonzero"); // ext-warning {{'_Static_assert' is a C11 extension}}
34 _Static_assert(0, "0 is nonzero"); // expected-error {{static_assert failed "0 is nonzero"}} \
35 // ext-warning {{'_Static_assert' is a C11 extension}}
37 static_assert(1, "1 is nonzero"); // ms-warning {{use of 'static_assert' without}}
42 #define ASSERT_IS_TYPE(T) __is_same(T, T)
44 #define ASSERT_IS_TYPE(T) __builtin_types_compatible_p(T, T)
47 #define UNION(T1, T2) union { \
50 _Static_assert(ASSERT_IS_TYPE(T1), "T1 is not a type"); \
51 _Static_assert(ASSERT_IS_TYPE(T2), "T2 is not a type"); \
52 _Static_assert(sizeof(T1) == sizeof(T2), "type size mismatch"); \
55 typedef UNION(unsigned, struct A
) U1
; // ext-warning 3 {{'_Static_assert' is a C11 extension}}
56 UNION(char[2], short) u2
= { .one
= { 'a', 'b' } }; // ext-warning 3 {{'_Static_assert' is a C11 extension}} cxx-warning {{designated initializers are a C++20 extension}}
57 typedef UNION(char, short) U3
; // expected-error {{static_assert failed due to requirement 'sizeof(char) == sizeof(short)' "type size mismatch"}} \
58 // ext-warning 3 {{'_Static_assert' is a C11 extension}}
59 typedef UNION(float, 0.5f
) U4
; // expected-error {{expected a type}} \
60 // ext-warning 3 {{'_Static_assert' is a C11 extension}}
62 // After defining the assert macro in MS-compatibility mode, we should
63 // no longer warn about including <assert.h> under the assumption the
64 // user already did that.
67 static_assert(1, "1 is nonzero"); // ok
69 // But we should still warn if the user did something bonkers.
71 static_assert(1, "1 is nonzero"); // ms-warning {{use of 'static_assert' without}}