xref: /minix3/external/bsd/llvm/dist/clang/test/Headers/limits.cpp (revision f4a2713ac843a11c696ec80c0a5e3e5d80b4d338)
1*f4a2713aSLionel Sambuc // RUN: %clang_cc1 -ffreestanding -fsyntax-only -verify %s
2*f4a2713aSLionel Sambuc // RUN: %clang_cc1 -fno-signed-char -ffreestanding -fsyntax-only -verify %s
3*f4a2713aSLionel Sambuc // RUN: %clang_cc1 -std=c++11 -ffreestanding -fsyntax-only -verify %s
4*f4a2713aSLionel Sambuc // expected-no-diagnostics
5*f4a2713aSLionel Sambuc 
6*f4a2713aSLionel Sambuc #include <limits.h>
7*f4a2713aSLionel Sambuc 
8*f4a2713aSLionel Sambuc _Static_assert(SCHAR_MAX == -(SCHAR_MIN+1), "");
9*f4a2713aSLionel Sambuc _Static_assert(SHRT_MAX == -(SHRT_MIN+1), "");
10*f4a2713aSLionel Sambuc _Static_assert(INT_MAX == -(INT_MIN+1), "");
11*f4a2713aSLionel Sambuc _Static_assert(LONG_MAX == -(LONG_MIN+1L), "");
12*f4a2713aSLionel Sambuc 
13*f4a2713aSLionel Sambuc _Static_assert(SCHAR_MAX == UCHAR_MAX/2, "");
14*f4a2713aSLionel Sambuc _Static_assert(SHRT_MAX == USHRT_MAX/2, "");
15*f4a2713aSLionel Sambuc _Static_assert(INT_MAX == UINT_MAX/2, "");
16*f4a2713aSLionel Sambuc _Static_assert(LONG_MAX == ULONG_MAX/2, "");
17*f4a2713aSLionel Sambuc 
18*f4a2713aSLionel Sambuc _Static_assert(SCHAR_MIN == -SCHAR_MAX-1, "");
19*f4a2713aSLionel Sambuc _Static_assert(SHRT_MIN == -SHRT_MAX-1, "");
20*f4a2713aSLionel Sambuc _Static_assert(INT_MIN == -INT_MAX-1, "");
21*f4a2713aSLionel Sambuc _Static_assert(LONG_MIN == -LONG_MAX-1L, "");
22*f4a2713aSLionel Sambuc 
23*f4a2713aSLionel Sambuc _Static_assert(UCHAR_MAX == (unsigned char)~0ULL, "");
24*f4a2713aSLionel Sambuc _Static_assert(USHRT_MAX == (unsigned short)~0ULL, "");
25*f4a2713aSLionel Sambuc _Static_assert(UINT_MAX == (unsigned int)~0ULL, "");
26*f4a2713aSLionel Sambuc _Static_assert(ULONG_MAX == (unsigned long)~0ULL, "");
27*f4a2713aSLionel Sambuc 
28*f4a2713aSLionel Sambuc _Static_assert(MB_LEN_MAX >= 1, "");
29*f4a2713aSLionel Sambuc 
30*f4a2713aSLionel Sambuc _Static_assert(CHAR_BIT >= 8, "");
31*f4a2713aSLionel Sambuc 
32*f4a2713aSLionel Sambuc const bool char_is_signed = (char)-1 < (char)0;
33*f4a2713aSLionel Sambuc _Static_assert(CHAR_MIN == (char_is_signed ? -CHAR_MAX-1 : 0), "");
34*f4a2713aSLionel Sambuc _Static_assert(CHAR_MAX == (char_is_signed ? -(CHAR_MIN+1) : (char)~0ULL), "");
35*f4a2713aSLionel Sambuc 
36*f4a2713aSLionel Sambuc #if __STDC_VERSION__ >= 199901 || __cplusplus >= 201103L
37*f4a2713aSLionel Sambuc _Static_assert(LLONG_MAX == -(LLONG_MIN+1LL), "");
38*f4a2713aSLionel Sambuc _Static_assert(LLONG_MIN == -LLONG_MAX-1LL, "");
39*f4a2713aSLionel Sambuc _Static_assert(ULLONG_MAX == (unsigned long long)~0ULL, "");
40*f4a2713aSLionel Sambuc #else
41*f4a2713aSLionel Sambuc int LLONG_MIN, LLONG_MAX, ULLONG_MAX; // Not defined.
42*f4a2713aSLionel Sambuc #endif
43