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

Marshall Clow via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Sun Feb 10 11:35:23 PST 2019


mclow.lists added inline comments.


================
Comment at: test/std/numerics/c.math/abs.fail.cpp:21
+    std::abs(ui); // expected-error {{call to 'abs' is ambiguous}}
+    
+    return 0;
----------------
EricWF wrote:
> More tests for `unsigned char`, `unsigned short`, `unsigned long`, and `unsigned long long`?
No. std::abs is not defined for unsigned types.



================
Comment at: test/std/numerics/c.math/abs.pass.cpp:27
+    
+    ASSERT_SAME_TYPE(decltype(std::abs(neg_val)), R);
+                     
----------------
EricWF wrote:
> I think this test for the return type can be simplified. We expect `std::abs(T)` to return `U` where `U` is the result of [integral promotion](https://en.cppreference.com/w/cpp/language/implicit_conversion)  on `T`.
> 
> Instead of hard-coding the expected type, we can calculate it using the expression `using R = decltype(+pos_value);`
I suggested that Zoe be explicit here.


================
Comment at: test/std/numerics/c.math/abs.pass.cpp:40
+
+int main(int, char**)
+{
----------------
EricWF wrote:
> `int main()` is fine. Same with omitting `return 0;`.
Not with the new freestanding stuff that Louis is working on


================
Comment at: test/std/numerics/c.math/abs.pass.cpp:54
+    test_abs<std::int32_t, int>();
+    test_abs<std::int64_t, long long>();
+    
----------------
EricWF wrote:
> This is non-portable. AFAIK there is no reason why `int64_t` can't be `long` on 64 bit platforms. 
> Using the integral promotion approach avoids this.
this is true.


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

https://reviews.llvm.org/D57778





More information about the libcxx-commits mailing list