[libcxx-commits] [PATCH] D57778: std::abs should not return double (2735)
Marshall Clow via Phabricator via libcxx-commits
libcxx-commits at lists.llvm.org
Mon Aug 19 18:15:37 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>();
----------------
zoecarver wrote:
> mclow.lists wrote:
> > 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>();`
> >
> I added this to `test_abs` so we always use it.
You should pull this out of this function, and put it into the template parameter list, because it shouldn't apply to floating point types.
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D57778/new/
https://reviews.llvm.org/D57778
More information about the libcxx-commits
mailing list