1 // RUN: %clang_cc1 -ffreestanding -fsyntax-only -verify %s
2 // RUN: %clang_cc1 -fno-signed-char -ffreestanding -fsyntax-only -verify %s
3 // RUN: %clang_cc1 -std=c++11 -ffreestanding -fsyntax-only -verify %s
4 // RUN: %clang_cc1 -std=c17 -ffreestanding -fsyntax-only -verify -x c %s
5 // RUN: %clang_cc1 -std=c2x -ffreestanding -fsyntax-only -verify -x c %s
7 // Specifically test 16-bit int platforms.
8 // RUN: %clang_cc1 -triple=avr -ffreestanding -fsyntax-only -verify -x c %s
9 // RUN: %clang_cc1 -triple=avr -std=c++11 -ffreestanding -fsyntax-only -verify %s
11 // expected-no-diagnostics
16 #define EXPR_TYPE_IS(EXPR, TYP) __is_same(__typeof(EXPR), TYP)
18 #define EXPR_TYPE_IS(EXPR, TYP) _Generic(EXPR, TYP: 1, default: 0)
21 _Static_assert(SCHAR_MAX
== -(SCHAR_MIN
+1), "");
22 _Static_assert(EXPR_TYPE_IS(SCHAR_MAX
, int), "");
26 _Static_assert(SHRT_MAX
== -(SHRT_MIN
+1), "");
27 _Static_assert(EXPR_TYPE_IS(SHRT_MAX
, int), "");
31 _Static_assert(INT_MAX
== -(INT_MIN
+1), "");
32 _Static_assert(EXPR_TYPE_IS(INT_MAX
, int), "");
36 _Static_assert(LONG_MAX
== -(LONG_MIN
+1L), "");
37 _Static_assert(EXPR_TYPE_IS(LONG_MAX
, long), "");
41 _Static_assert(SCHAR_MAX
== UCHAR_MAX
/2, "");
42 _Static_assert(SHRT_MAX
== USHRT_MAX
/2, "");
43 _Static_assert(INT_MAX
== UINT_MAX
/2, "");
44 _Static_assert(LONG_MAX
== ULONG_MAX
/2, "");
46 _Static_assert(SCHAR_MIN
== -SCHAR_MAX
-1, "");
47 _Static_assert(EXPR_TYPE_IS(SCHAR_MIN
, int), "");
51 _Static_assert(SHRT_MIN
== -SHRT_MAX
-1, "");
52 _Static_assert(EXPR_TYPE_IS(SHRT_MIN
, int), "");
56 _Static_assert(INT_MIN
== -INT_MAX
-1, "");
57 _Static_assert(EXPR_TYPE_IS(INT_MIN
, int), "");
61 _Static_assert(LONG_MIN
== -LONG_MAX
-1L, "");
62 _Static_assert(EXPR_TYPE_IS(LONG_MIN
, long), "");
66 _Static_assert(UCHAR_MAX
== (unsigned char)~0ULL, "");
67 _Static_assert(UCHAR_MAX
<= INT_MAX
?
68 EXPR_TYPE_IS(UCHAR_MAX
, int) :
69 EXPR_TYPE_IS(UCHAR_MAX
, unsigned int), "");
73 _Static_assert(USHRT_MAX
== (unsigned short)~0ULL, "");
74 _Static_assert(USHRT_MAX
<= INT_MAX
?
75 EXPR_TYPE_IS(USHRT_MAX
, int) :
76 EXPR_TYPE_IS(USHRT_MAX
, unsigned int), "");
80 _Static_assert(UINT_MAX
== (unsigned int)~0ULL, "");
81 _Static_assert(EXPR_TYPE_IS(UINT_MAX
, unsigned int), "");
85 _Static_assert(ULONG_MAX
== (unsigned long)~0ULL, "");
86 _Static_assert(EXPR_TYPE_IS(ULONG_MAX
, unsigned long), "");
90 _Static_assert(MB_LEN_MAX
>= 1, "");
94 _Static_assert(CHAR_BIT
>= 8, "");
98 _Static_assert(CHAR_MIN
== (((char)-1 < (char)0) ? -CHAR_MAX
-1 : 0), "");
99 _Static_assert(EXPR_TYPE_IS(CHAR_MIN
, int), "");
103 _Static_assert(CHAR_MAX
== (((char)-1 < (char)0) ? -(CHAR_MIN
+1) : (char)~0ULL), "");
104 _Static_assert(CHAR_MAX
<= INT_MAX
?
105 EXPR_TYPE_IS(CHAR_MAX
, int) :
106 EXPR_TYPE_IS(CHAR_MAX
, unsigned int), "");
110 #if __STDC_VERSION__ >= 199901 || __cplusplus >= 201103L
111 _Static_assert(LLONG_MAX
== -(LLONG_MIN
+1LL), "");
112 _Static_assert(EXPR_TYPE_IS(LLONG_MAX
, long long), "");
116 _Static_assert(LLONG_MIN
== -LLONG_MAX
-1LL, "");
119 _Static_assert(EXPR_TYPE_IS(LLONG_MIN
, long long), "");
121 _Static_assert(ULLONG_MAX
== (unsigned long long)~0ULL, "");
122 _Static_assert(EXPR_TYPE_IS(ULLONG_MAX
, unsigned long long), "");
126 int LLONG_MIN
, LLONG_MAX
, ULLONG_MAX
; // Not defined.
129 #if __STDC_VERSION__ >= 202311L
130 /* Validate the standard requirements. */
131 _Static_assert(BOOL_WIDTH
>= 1);
135 _Static_assert(CHAR_WIDTH
== CHAR_BIT
);
136 _Static_assert(CHAR_WIDTH
/ CHAR_BIT
== sizeof(char));
139 _Static_assert(SCHAR_WIDTH
== CHAR_BIT
);
140 _Static_assert(SCHAR_WIDTH
/ CHAR_BIT
== sizeof(signed char));
143 _Static_assert(UCHAR_WIDTH
== CHAR_BIT
);
144 _Static_assert(UCHAR_WIDTH
/ CHAR_BIT
== sizeof(unsigned char));
148 _Static_assert(USHRT_WIDTH
>= 16);
149 _Static_assert(USHRT_WIDTH
/ CHAR_BIT
== sizeof(unsigned short));
152 _Static_assert(SHRT_WIDTH
== USHRT_WIDTH
);
153 _Static_assert(SHRT_WIDTH
/ CHAR_BIT
== sizeof(signed short));
157 _Static_assert(UINT_WIDTH
>= 16);
158 _Static_assert(UINT_WIDTH
/ CHAR_BIT
== sizeof(unsigned int));
161 _Static_assert(INT_WIDTH
== UINT_WIDTH
);
162 _Static_assert(INT_WIDTH
/ CHAR_BIT
== sizeof(signed int));
166 _Static_assert(ULONG_WIDTH
>= 32);
167 _Static_assert(ULONG_WIDTH
/ CHAR_BIT
== sizeof(unsigned long));
170 _Static_assert(LONG_WIDTH
== ULONG_WIDTH
);
171 _Static_assert(LONG_WIDTH
/ CHAR_BIT
== sizeof(signed long));
175 _Static_assert(ULLONG_WIDTH
>= 64);
176 _Static_assert(ULLONG_WIDTH
/ CHAR_BIT
== sizeof(unsigned long long));
179 _Static_assert(LLONG_WIDTH
== ULLONG_WIDTH
);
180 _Static_assert(LLONG_WIDTH
/ CHAR_BIT
== sizeof(signed long long));
184 _Static_assert(BITINT_MAXWIDTH
>= ULLONG_WIDTH
);
188 /* None of these are defined. */
189 int BOOL_WIDTH
, CHAR_WIDTH
, SCHAR_WIDTH
, UCHAR_WIDTH
, USHRT_WIDTH
, SHRT_WIDTH
,
190 UINT_WIDTH
, INT_WIDTH
, ULONG_WIDTH
, LONG_WIDTH
, ULLONG_WIDTH
, LLONG_WIDTH
,