[libcxx-commits] [PATCH] D57778: std::abs should not return double (2735)

Zoe Carver via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Thu Aug 15 09:30:51 PDT 2019


zoecarver marked an inline comment as done.
zoecarver 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>();
----------------
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.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D57778/new/

https://reviews.llvm.org/D57778





More information about the libcxx-commits mailing list