[libcxx-commits] [PATCH] D57778: std::abs should not return double (2735)
Zoe Carver via Phabricator via libcxx-commits
libcxx-commits at lists.llvm.org
Tue Aug 20 13:05:25 PDT 2019
zoecarver updated this revision to Diff 216223.
zoecarver added a comment.
Remove correct int type trait (as it is not needed and adds complexity)
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D57778/new/
https://reviews.llvm.org/D57778
Files:
libcxx/test/std/numerics/c.math/abs.pass.cpp
Index: libcxx/test/std/numerics/c.math/abs.pass.cpp
===================================================================
--- libcxx/test/std/numerics/c.math/abs.pass.cpp
+++ libcxx/test/std/numerics/c.math/abs.pass.cpp
@@ -13,12 +13,6 @@
#include "test_macros.h"
-template<class T>
-struct correct_size_int
-{
- typedef typename std::conditional<sizeof(T) <= sizeof(int), int, T>::type type;
-};
-
template <class Source, class Result>
void test_abs()
{
@@ -39,6 +33,9 @@
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,18 +44,20 @@
std::is_signed<char>::value, char, signed char
>::type SignedChar;
- test_abs<short int, typename correct_size_int<short int>::type>();
- test_abs<SignedChar, typename correct_size_int<SignedChar>::type>();
- test_abs<signed char, typename correct_size_int<signed char>::type>();
+ // All types less than or equal to and not greater than int are promoted to int.
+ test_abs<short int, int>();
+ test_abs<SignedChar, int>();
+ test_abs<signed char, int>();
- test_abs<int, typename correct_size_int<int>::type>();
- test_abs<long int, typename correct_size_int<long int>::type>();
- test_abs<long long int, typename correct_size_int<long long int>::type>();
+ // These three calls have specific overloads:
+ test_abs<int, int>();
+ test_abs<long int, long int>();
+ test_abs<long long int, long long int>();
- test_abs<std::int8_t, typename correct_size_int<std::int8_t>::type>();
- test_abs<std::int16_t, typename correct_size_int<std::int16_t>::type>();
- test_abs<std::int32_t, typename correct_size_int<std::int32_t>::type>();
- test_abs<std::int64_t, typename correct_size_int<std::int64_t>::type>();
+ test_abs<std::int8_t, std::int32_t>();
+ test_abs<std::int16_t, std::int32_t>();
+ test_abs<std::int32_t, std::int32_t>();
+ test_abs<std::int64_t, std::int64_t>();
test_abs<long double, long double>();
test_abs<double, double>();
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D57778.216223.patch
Type: text/x-patch
Size: 2222 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libcxx-commits/attachments/20190820/efece8d6/attachment-0001.bin>
More information about the libcxx-commits
mailing list