48 lines · c
1// RUN: %clang_cc1 -verify %s2 3/* WG14 N736: yes4 * preprocessor arithmetic done in intmax_t/uintmax_t5 */6 7// There is not a standard requirement that this relationships holds. If these8// asserts fail, it means we have another test scenario to consider.9_Static_assert(__INTMAX_MAX__ == __LONG_LONG_MAX__,10 "intmax_t is not the same width as long long?");11_Static_assert((-__INTMAX_MAX__ - 1) == (-__LONG_LONG_MAX__ - 1LL),12 "intmax_t is not the same width as long long?");13_Static_assert(__UINTMAX_MAX__ == (__LONG_LONG_MAX__ * 2ULL + 1ULL),14 "uintmax_t is not the same width as unsigned long long?");15 16// Test that arithmetic on the largest positive signed intmax_t works.17#if 9223372036854775807LL + 0LL != 9223372036854775807LL18#error "uh oh"19#endif20 21// Same for negative.22#if -9223372036854775807LL - 1LL + 0LL != -9223372036854775807LL - 1LL23#error "uh oh"24#endif25 26// Then test the same for unsigned27#if 18446744073709551615ULL + 0ULL != 18446744073709551615ULL28#error "uh oh"29#endif30 31// Test that unsigned overflow causes silent wraparound.32#if 18446744073709551615ULL + 1ULL != 0 // Silently wraps to 0.33#error "uh oh"34#endif35 36#if 0ULL - 1ULL != 18446744073709551615ULL // Silently wraps to 0xFFFF'FFFF'FFFF'FFFF.37#error "uh oh"38#endif39 40// Now test that signed arithmetic that pushes us over a limit is properly41// diagnosed.42#if 9223372036854775807LL + 1LL // expected-warning {{integer overflow in preprocessor expression}}43#endif44 45#if -9223372036854775807LL - 2LL // expected-warning {{integer overflow in preprocessor expression}}46#endif47 48