From e44fcf8346d06daee2176ae6a39a18c5f8043dc3 Mon Sep 17 00:00:00 2001 From: Zoe Carver Date: Tue, 20 Aug 2019 20:44:59 +0000 Subject: [PATCH] [libc++] Fix std::abs tests On systems where sizeof(long) == sizeof(int) the current tests failed. This commit updates those tests to work on all systems. std::abs has specific long specializations which can be used instead. git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@369437 91177308-0d34-0410-b5e6-96231b3b80d8 --- test/std/numerics/c.math/abs.pass.cpp | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/test/std/numerics/c.math/abs.pass.cpp b/test/std/numerics/c.math/abs.pass.cpp index 33e0c7d64..bdca9a616 100644 --- a/test/std/numerics/c.math/abs.pass.cpp +++ b/test/std/numerics/c.math/abs.pass.cpp @@ -16,7 +16,7 @@ template struct correct_size_int { - typedef typename std::conditional::type type; + typedef typename std::conditional::type type; }; template @@ -39,6 +39,9 @@ void test_big() assert(std::abs(negative_big_value) == big_value); // make sure it doesnt get casted to a smaller type } +// The following is helpful to keep in mind: +// 1byte == char <= short <= int <= long <= long long + int main(int, char**) { // On some systems char is unsigned. @@ -47,14 +50,18 @@ int main(int, char**) std::is_signed::value, char, signed char >::type SignedChar; - test_abs::type>(); - test_abs::type>(); - test_abs::type>(); + // All types less than or equal to and not greater than int are promoted to int. + test_abs(); + test_abs(); + test_abs(); - test_abs::type>(); - test_abs::type>(); - test_abs::type>(); + // These three calls have specific overloads: + test_abs(); + test_abs(); + test_abs(); + // Here there is no guarantee that int is larger than int8_t so we + // use a helper type trait to conditional test against int. test_abs::type>(); test_abs::type>(); test_abs::type>();