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

Marshall Clow via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Tue Feb 5 21:50:14 PST 2019


mclow.lists added inline comments.


================
Comment at: test/std/numerics/c.math/abs.fail.cpp:9
+
+#include <cstdlib>
+
----------------
Is this the right file to include - or should it be `<cmath>`?


================
Comment at: test/std/numerics/c.math/abs.fail.cpp:17
+
+int main()
+{
----------------
As of yesterday, we always write main as `int main (int, char**)`


================
Comment at: test/std/numerics/c.math/abs.pass.cpp:19
+
+template <class T>
+void test_abs()
----------------
I would add a second template parameter here, that is the expected return type.
Some thing like:

```
template <class Source, class Result>
void test_abs()
{
    T neg_val = -5;
    T pos_val = 5;
    Result res = 5;

    ASSERT_SAME_TYPE(Result, decltype(std::abs(T));

    assert(std::abs(neg_val) == res);
    assert(std::abs(pos_val) == res);
}
```



================
Comment at: test/std/numerics/c.math/abs.pass.cpp:50
+    // make sure that short is upgraded to int
+    ASSERT_SAME_TYPE(decltype(std::abs((short int) -5)), int);
+    
----------------
By adding the second template parameter to test_abs, this line becomes redundant.


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

https://reviews.llvm.org/D57778





More information about the libcxx-commits mailing list