On Sat, Oct 26, 2013 at 4:16 PM, JF Bastien <[email protected]> wrote: > I couldn't find a pre-existing test for this file, how about I add the > following as tools/clang/test/Headers/limits.cpp : >
SGTM, go ahead, thanks! > // 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_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, ""); > It'd be nice to test that the values are actually correct, as well as that they are in matching pairs. Something like: (unsigned char)SCHAR_MIN == (unsigned char)SCHAR_MAX + 1 ... should do the trick. > _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, ""); > Maybe: #else int LLONG_MIN, LLONG_MAX, ULLONG_MAX; // not defined > #endif > > > On Fri, Oct 25, 2013 at 3:43 PM, Richard Smith <[email protected]> > wrote: > > Please add a test for this. Otherwise LGTM. > > > > On 22 Oct 2013 16:02, "JF Bastien" <[email protected]> wrote: > >> > >> C99 has LLONG_MIN, LLONG_MAX, ULLONG_MAX and so does C++11. Teach > clang's > >> limits.h about it. > >> > >> diff --git a/lib/Headers/limits.h b/lib/Headers/limits.h > >> index ecd09a4..91bd404 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 > >> > >> > >> _______________________________________________ > >> cfe-commits mailing list > >> [email protected] > >> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits > >> > > >
_______________________________________________ cfe-commits mailing list [email protected] http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
