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 6 // expected-no-diagnostics 7 8 #include <limits.h> 9 10 _Static_assert(SCHAR_MAX == -(SCHAR_MIN+1), ""); 11 _Static_assert(SHRT_MAX == -(SHRT_MIN+1), ""); 12 _Static_assert(INT_MAX == -(INT_MIN+1), ""); 13 _Static_assert(LONG_MAX == -(LONG_MIN+1L), ""); 14 15 _Static_assert(SCHAR_MAX == UCHAR_MAX/2, ""); 16 _Static_assert(SHRT_MAX == USHRT_MAX/2, ""); 17 _Static_assert(INT_MAX == UINT_MAX/2, ""); 18 _Static_assert(LONG_MAX == ULONG_MAX/2, ""); 19 20 _Static_assert(SCHAR_MIN == -SCHAR_MAX-1, ""); 21 _Static_assert(SHRT_MIN == -SHRT_MAX-1, ""); 22 _Static_assert(INT_MIN == -INT_MAX-1, ""); 23 _Static_assert(LONG_MIN == -LONG_MAX-1L, ""); 24 25 _Static_assert(UCHAR_MAX == (unsigned char)~0ULL, ""); 26 _Static_assert(USHRT_MAX == (unsigned short)~0ULL, ""); 27 _Static_assert(UINT_MAX == (unsigned int)~0ULL, ""); 28 _Static_assert(ULONG_MAX == (unsigned long)~0ULL, ""); 29 30 _Static_assert(MB_LEN_MAX >= 1, ""); 31 32 _Static_assert(CHAR_BIT >= 8, ""); 33 34 _Static_assert(CHAR_MIN == (((char)-1 < (char)0) ? -CHAR_MAX-1 : 0), ""); 35 _Static_assert(CHAR_MAX == (((char)-1 < (char)0) ? -(CHAR_MIN+1) : (char)~0ULL), ""); 36 37 #if __STDC_VERSION__ >= 199901 || __cplusplus >= 201103L 38 _Static_assert(LLONG_MAX == -(LLONG_MIN+1LL), ""); 39 _Static_assert(LLONG_MIN == -LLONG_MAX-1LL, ""); 40 _Static_assert(ULLONG_MAX == (unsigned long long)~0ULL, ""); 41 #else 42 int LLONG_MIN, LLONG_MAX, ULLONG_MAX; // Not defined. 43 #endif 44 45 /* FIXME: This is using the placeholder dates Clang produces for these macros 46 in C2x mode; switch to the correct values once they've been published. */ 47 #if __STDC_VERSION__ >= 202000L 48 /* Validate the standard requirements. */ 49 _Static_assert(BOOL_WIDTH >= 1); 50 51 _Static_assert(CHAR_WIDTH == CHAR_BIT); 52 _Static_assert(CHAR_WIDTH / CHAR_BIT == sizeof(char)); 53 _Static_assert(SCHAR_WIDTH == CHAR_BIT); 54 _Static_assert(SCHAR_WIDTH / CHAR_BIT == sizeof(signed char)); 55 _Static_assert(UCHAR_WIDTH == CHAR_BIT); 56 _Static_assert(UCHAR_WIDTH / CHAR_BIT == sizeof(unsigned char)); 57 58 _Static_assert(USHRT_WIDTH >= 16); 59 _Static_assert(USHRT_WIDTH / CHAR_BIT == sizeof(unsigned short)); 60 _Static_assert(SHRT_WIDTH == USHRT_WIDTH); 61 _Static_assert(SHRT_WIDTH / CHAR_BIT == sizeof(signed short)); 62 63 _Static_assert(UINT_WIDTH >= 16); 64 _Static_assert(UINT_WIDTH / CHAR_BIT == sizeof(unsigned int)); 65 _Static_assert(INT_WIDTH == UINT_WIDTH); 66 _Static_assert(INT_WIDTH / CHAR_BIT == sizeof(signed int)); 67 68 _Static_assert(ULONG_WIDTH >= 32); 69 _Static_assert(ULONG_WIDTH / CHAR_BIT == sizeof(unsigned long)); 70 _Static_assert(LONG_WIDTH == ULONG_WIDTH); 71 _Static_assert(LONG_WIDTH / CHAR_BIT == sizeof(signed long)); 72 73 _Static_assert(ULLONG_WIDTH >= 64); 74 _Static_assert(ULLONG_WIDTH / CHAR_BIT == sizeof(unsigned long long)); 75 _Static_assert(LLONG_WIDTH == ULLONG_WIDTH); 76 _Static_assert(LLONG_WIDTH / CHAR_BIT == sizeof(signed long long)); 77 78 _Static_assert(BITINT_MAXWIDTH >= ULLONG_WIDTH); 79 #else 80 /* None of these are defined. */ 81 int BOOL_WIDTH, CHAR_WIDTH, SCHAR_WIDTH, UCHAR_WIDTH, USHRT_WIDTH, SHRT_WIDTH, 82 UINT_WIDTH, INT_WIDTH, ULONG_WIDTH, LONG_WIDTH, ULLONG_WIDTH, LLONG_WIDTH, 83 BITINT_MAXWIDTH; 84 #endif 85