[libcxx-commits] [PATCH] D57778: std::abs should not return double (2735)
Marshall Clow via Phabricator via libcxx-commits
libcxx-commits at lists.llvm.org
Thu Aug 15 08:15:12 PDT 2019
mclow.lists added inline comments.
================
Comment at: libcxx/test/std/numerics/c.math/abs.pass.cpp:51
+ test_abs<std::int16_t, int>();
+ test_abs<std::int32_t, int>();
+ test_abs<std::int64_t, std::int64_t>();
----------------
I think these tests are nonportable. The assumption here is that `int32_t` (and others) are smaller than (or the same size as) `int`, and `int64_t` is larger.
Maybe you want a little type trait (untested)
```
template <typename T> struct smaller_than_int {
typedef typename std::conditional<sizeof(T) < sizeof(int), int, T>::type type;
};
```
and then write `test_abs<std::int8_t, smaller_than_int <std::int8_t>();`
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D57778/new/
https://reviews.llvm.org/D57778
More information about the libcxx-commits
mailing list