1 // RUN: %clang_cc1 -std=c11 -fsyntax-only -verify %s
2 // RUN: %clang_cc1 -xc++ -std=c++11 -fsyntax-only -verify %s
4 _Static_assert("foo", "string is nonzero");
6 // expected-error@-2 {{static_assert expression is not an integral constant expression}}
9 _Static_assert(1, "1 is nonzero");
10 _Static_assert(0, "0 is nonzero"); // expected-error {{static_assert failed "0 is nonzero"}}
13 _Static_assert(1, "1 is nonzero");
14 _Static_assert(0, "0 is nonzero"); // expected-error {{static_assert failed "0 is nonzero"}}
17 _Static_assert(1, invalid); // expected-error {{expected string literal for diagnostic message in static_assert}}
21 _Static_assert(1, "1 is nonzero");
22 _Static_assert(0, "0 is nonzero"); // expected-error {{static_assert failed "0 is nonzero"}}
26 #define ASSERT_IS_TYPE(T) __is_same(T, T)
28 #define ASSERT_IS_TYPE(T) __builtin_types_compatible_p(T, T)
31 #define UNION(T1, T2) union { \
34 _Static_assert(ASSERT_IS_TYPE(T1), "T1 is not a type"); \
35 _Static_assert(ASSERT_IS_TYPE(T2), "T2 is not a type"); \
36 _Static_assert(sizeof(T1) == sizeof(T2), "type size mismatch"); \
39 typedef UNION(unsigned, struct A) U1;
40 UNION(char[2], short) u2 = { .one = { 'a', 'b' } };
41 typedef UNION(char, short) U3; // expected-error {{static_assert failed "type size mismatch"}}
42 typedef UNION(float, 0.5f) U4; // expected-error {{expected a type}}