diff options
author | JF Bastien <jfb@chromium.org> | 2013-10-28 08:58:05 -0700 |
---|---|---|
committer | JF Bastien <jfb@chromium.org> | 2013-10-28 08:58:05 -0700 |
commit | 5b8e932d70fcf281e193aebfd0d3ac55d057f2da (patch) | |
tree | 232595404c15e117af80f0415622ce3a6c331d0e | |
parent | 96f3e19c98507a181be89a85f6e7b4db711a3f45 (diff) |
Cherry-pick upstream clang r193506: "Define [U]LLONG_{MIN,MAX} for C++11, add tests."
This is needed for libc++ testing with newlib.
R=dschuff@chromium.org
BUG= https://code.google.com/p/nativeclient/issues/detail?id=3623
TEST= ./pnacl/scripts/llvm-test.py --libcxx-tests
Review URL: https://codereview.chromium.org/47573003
-rw-r--r-- | lib/Headers/limits.h | 6 | ||||
-rw-r--r-- | test/Headers/limits.cpp | 42 |
2 files changed, 46 insertions, 2 deletions
diff --git a/lib/Headers/limits.h b/lib/Headers/limits.h index ecd09a4a24..91bd404650 100644 --- a/lib/Headers/limits.h +++ b/lib/Headers/limits.h @@ -87,8 +87,10 @@ #define CHAR_MAX __SCHAR_MAX__ #endif -/* C99 5.2.4.2.1: Added long long. */ -#if __STDC_VERSION__ >= 199901 +/* C99 5.2.4.2.1: Added long long. + C++11 18.3.3.2: same contents as the Standard C Library header <limits.h>. + */ +#if __STDC_VERSION__ >= 199901 || __cplusplus >= 201103L #undef LLONG_MIN #undef LLONG_MAX diff --git a/test/Headers/limits.cpp b/test/Headers/limits.cpp new file mode 100644 index 0000000000..a78f7fc6de --- /dev/null +++ b/test/Headers/limits.cpp @@ -0,0 +1,42 @@ +// RUN: %clang_cc1 -ffreestanding -fsyntax-only -verify %s +// RUN: %clang_cc1 -fno-signed-char -ffreestanding -fsyntax-only -verify %s +// RUN: %clang_cc1 -std=c++11 -ffreestanding -fsyntax-only -verify %s +// expected-no-diagnostics + +#include <limits.h> + +_Static_assert(SCHAR_MAX == -(SCHAR_MIN+1), ""); +_Static_assert(SHRT_MAX == -(SHRT_MIN+1), ""); +_Static_assert(INT_MAX == -(INT_MIN+1), ""); +_Static_assert(LONG_MAX == -(LONG_MIN+1L), ""); + +_Static_assert(SCHAR_MAX == UCHAR_MAX/2, ""); +_Static_assert(SHRT_MAX == USHRT_MAX/2, ""); +_Static_assert(INT_MAX == UINT_MAX/2, ""); +_Static_assert(LONG_MAX == ULONG_MAX/2, ""); + +_Static_assert(SCHAR_MIN == -SCHAR_MAX-1, ""); +_Static_assert(SHRT_MIN == -SHRT_MAX-1, ""); +_Static_assert(INT_MIN == -INT_MAX-1, ""); +_Static_assert(LONG_MIN == -LONG_MAX-1L, ""); + +_Static_assert(UCHAR_MAX == (unsigned char)~0ULL, ""); +_Static_assert(USHRT_MAX == (unsigned short)~0ULL, ""); +_Static_assert(UINT_MAX == (unsigned int)~0ULL, ""); +_Static_assert(ULONG_MAX == (unsigned long)~0ULL, ""); + +_Static_assert(MB_LEN_MAX >= 1, ""); + +_Static_assert(CHAR_BIT >= 8, ""); + +const bool char_is_signed = (char)-1 < (char)0; +_Static_assert(CHAR_MIN == (char_is_signed ? -CHAR_MAX-1 : 0), ""); +_Static_assert(CHAR_MAX == (char_is_signed ? -(CHAR_MIN+1) : (char)~0ULL), ""); + +#if __STDC_VERSION__ >= 199901 || __cplusplus >= 201103L +_Static_assert(LLONG_MAX == -(LLONG_MIN+1LL), ""); +_Static_assert(LLONG_MIN == -LLONG_MAX-1LL, ""); +_Static_assert(ULLONG_MAX == (unsigned long long)~0ULL, ""); +#else +int LLONG_MIN, LLONG_MAX, ULLONG_MAX; // Not defined. +#endif |