From 80ddfcb5b813a61bc75b8a8db0144416d7a47226 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. llvm-svn: 369437 --- libcxx/test/std/numerics/c.math/abs.pass.cpp | 21 +++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/libcxx/test/std/numerics/c.math/abs.pass.cpp b/libcxx/test/std/numerics/c.math/abs.pass.cpp index 33e0c7d64c46..bdca9a616ec8 100644 --- a/libcxx/test/std/numerics/c.math/abs.pass.cpp +++ b/libcxx/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>();