[clang] Implement lifetime analysis for lifetime_capture_by(X) (#115921)
[llvm-project.git] / clang / test / Headers / limits.cpp
blob132e5bc24a0c929e792207d2b599f09b116e0f46
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 arm64 linux platforms.
8 // RUN: %clang_cc1 -triple arm64-linux -ffreestanding -fsyntax-only -verify -x c %s
10 // Specifically test 16-bit int platforms.
11 // RUN: %clang_cc1 -triple=avr -ffreestanding -fsyntax-only -verify -x c %s
12 // RUN: %clang_cc1 -triple=avr -std=c++11 -ffreestanding -fsyntax-only -verify %s
14 // expected-no-diagnostics
16 #include <limits.h>
18 #if __cplusplus
19 #define EXPR_TYPE_IS(EXPR, TYP) __is_same(__typeof(EXPR), TYP)
20 #else
21 #define EXPR_TYPE_IS(EXPR, TYP) _Generic(EXPR, TYP: 1, default: 0)
22 #endif
24 _Static_assert(SCHAR_MAX == -(SCHAR_MIN+1), "");
25 _Static_assert(EXPR_TYPE_IS(SCHAR_MAX, int), "");
26 #if SCHAR_MAX
27 #endif
29 _Static_assert(SHRT_MAX == -(SHRT_MIN+1), "");
30 _Static_assert(EXPR_TYPE_IS(SHRT_MAX, int), "");
31 #if SHRT_MAX
32 #endif
34 _Static_assert(INT_MAX == -(INT_MIN+1), "");
35 _Static_assert(EXPR_TYPE_IS(INT_MAX, int), "");
36 #if INT_MAX
37 #endif
39 _Static_assert(LONG_MAX == -(LONG_MIN+1L), "");
40 _Static_assert(EXPR_TYPE_IS(LONG_MAX, long), "");
41 #if LONG_MAX
42 #endif
44 _Static_assert(SCHAR_MAX == UCHAR_MAX/2, "");
45 _Static_assert(SHRT_MAX == USHRT_MAX/2, "");
46 _Static_assert(INT_MAX == UINT_MAX/2, "");
47 _Static_assert(LONG_MAX == ULONG_MAX/2, "");
49 _Static_assert(SCHAR_MIN == -SCHAR_MAX-1, "");
50 _Static_assert(EXPR_TYPE_IS(SCHAR_MIN, int), "");
51 #if SCHAR_MIN
52 #endif
54 _Static_assert(SHRT_MIN == -SHRT_MAX-1, "");
55 _Static_assert(EXPR_TYPE_IS(SHRT_MIN, int), "");
56 #if SHRT_MIN
57 #endif
59 _Static_assert(INT_MIN == -INT_MAX-1, "");
60 _Static_assert(EXPR_TYPE_IS(INT_MIN, int), "");
61 #if INT_MIN
62 #endif
64 _Static_assert(LONG_MIN == -LONG_MAX-1L, "");
65 _Static_assert(EXPR_TYPE_IS(LONG_MIN, long), "");
66 #if LONG_MIN
67 #endif
69 _Static_assert(UCHAR_MAX == (unsigned char)~0ULL, "");
70 _Static_assert(UCHAR_MAX <= INT_MAX ?
71 EXPR_TYPE_IS(UCHAR_MAX, int) :
72 EXPR_TYPE_IS(UCHAR_MAX, unsigned int), "");
73 #if UCHAR_MAX
74 #endif
76 _Static_assert(USHRT_MAX == (unsigned short)~0ULL, "");
77 _Static_assert(USHRT_MAX <= INT_MAX ?
78 EXPR_TYPE_IS(USHRT_MAX, int) :
79 EXPR_TYPE_IS(USHRT_MAX, unsigned int), "");
80 #if USHRT_MAX
81 #endif
83 _Static_assert(UINT_MAX == (unsigned int)~0ULL, "");
84 _Static_assert(EXPR_TYPE_IS(UINT_MAX, unsigned int), "");
85 #if UINT_MAX
86 #endif
88 _Static_assert(ULONG_MAX == (unsigned long)~0ULL, "");
89 _Static_assert(EXPR_TYPE_IS(ULONG_MAX, unsigned long), "");
90 #if ULONG_MAX
91 #endif
93 _Static_assert(MB_LEN_MAX >= 1, "");
94 #if MB_LEN_MAX
95 #endif
97 _Static_assert(CHAR_BIT >= 8, "");
98 #if CHAR_BIT
99 #endif
101 _Static_assert(CHAR_MIN == (((char)-1 < (char)0) ? -CHAR_MAX-1 : 0), "");
102 _Static_assert(EXPR_TYPE_IS(CHAR_MIN, int), "");
103 #if CHAR_MIN
104 #endif
106 _Static_assert(CHAR_MAX == (((char)-1 < (char)0) ? -(CHAR_MIN+1) : (char)~0ULL), "");
107 _Static_assert(CHAR_MAX <= INT_MAX ?
108 EXPR_TYPE_IS(CHAR_MAX, int) :
109 EXPR_TYPE_IS(CHAR_MAX, unsigned int), "");
110 #if CHAR_MAX
111 #endif
113 #if __STDC_VERSION__ >= 199901 || __cplusplus >= 201103L
114 _Static_assert(LLONG_MAX == -(LLONG_MIN+1LL), "");
115 _Static_assert(EXPR_TYPE_IS(LLONG_MAX, long long), "");
116 #if LLONG_MAX
117 #endif
119 _Static_assert(LLONG_MIN == -LLONG_MAX-1LL, "");
120 #if LLONG_MIN
121 #endif
122 _Static_assert(EXPR_TYPE_IS(LLONG_MIN, long long), "");
124 _Static_assert(ULLONG_MAX == (unsigned long long)~0ULL, "");
125 _Static_assert(EXPR_TYPE_IS(ULLONG_MAX, unsigned long long), "");
126 #if ULLONG_MAX
127 #endif
128 #else
129 int LLONG_MIN, LLONG_MAX, ULLONG_MAX; // Not defined.
130 #endif
132 #if __STDC_VERSION__ >= 202311L
133 /* Validate the standard requirements. */
134 _Static_assert(BOOL_WIDTH >= 1);
135 #if BOOL_WIDTH
136 #endif
138 _Static_assert(CHAR_WIDTH == CHAR_BIT);
139 _Static_assert(CHAR_WIDTH / CHAR_BIT == sizeof(char));
140 #if CHAR_WIDTH
141 #endif
142 _Static_assert(SCHAR_WIDTH == CHAR_BIT);
143 _Static_assert(SCHAR_WIDTH / CHAR_BIT == sizeof(signed char));
144 #if SCHAR_WIDTH
145 #endif
146 _Static_assert(UCHAR_WIDTH == CHAR_BIT);
147 _Static_assert(UCHAR_WIDTH / CHAR_BIT == sizeof(unsigned char));
148 #if UCHAR_WIDTH
149 #endif
151 _Static_assert(USHRT_WIDTH >= 16);
152 _Static_assert(USHRT_WIDTH / CHAR_BIT == sizeof(unsigned short));
153 #if USHRT_WIDTH
154 #endif
155 _Static_assert(SHRT_WIDTH == USHRT_WIDTH);
156 _Static_assert(SHRT_WIDTH / CHAR_BIT == sizeof(signed short));
157 #if SHRT_WIDTH
158 #endif
160 _Static_assert(UINT_WIDTH >= 16);
161 _Static_assert(UINT_WIDTH / CHAR_BIT == sizeof(unsigned int));
162 #if UINT_WIDTH
163 #endif
164 _Static_assert(INT_WIDTH == UINT_WIDTH);
165 _Static_assert(INT_WIDTH / CHAR_BIT == sizeof(signed int));
166 #if INT_WIDTH
167 #endif
169 _Static_assert(ULONG_WIDTH >= 32);
170 _Static_assert(ULONG_WIDTH / CHAR_BIT == sizeof(unsigned long));
171 #if ULONG_WIDTH
172 #endif
173 _Static_assert(LONG_WIDTH == ULONG_WIDTH);
174 _Static_assert(LONG_WIDTH / CHAR_BIT == sizeof(signed long));
175 #if LONG_WIDTH
176 #endif
178 _Static_assert(ULLONG_WIDTH >= 64);
179 _Static_assert(ULLONG_WIDTH / CHAR_BIT == sizeof(unsigned long long));
180 #if ULLONG_WIDTH
181 #endif
182 _Static_assert(LLONG_WIDTH == ULLONG_WIDTH);
183 _Static_assert(LLONG_WIDTH / CHAR_BIT == sizeof(signed long long));
184 #if LLONG_WIDTH
185 #endif
187 _Static_assert(BITINT_MAXWIDTH >= ULLONG_WIDTH);
188 #if BITINT_MAXWIDTH
189 #endif
190 #else
191 /* None of these are defined. */
192 int BOOL_WIDTH, CHAR_WIDTH, SCHAR_WIDTH, UCHAR_WIDTH, USHRT_WIDTH, SHRT_WIDTH,
193 UINT_WIDTH, INT_WIDTH, ULONG_WIDTH, LONG_WIDTH, ULLONG_WIDTH, LLONG_WIDTH,
194 BITINT_MAXWIDTH;
195 #endif