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

Zoe Carver via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Tue Aug 20 12:36:56 PDT 2019


zoecarver updated this revision to Diff 216216.
zoecarver added a comment.

On systems where `sizeof(long) == sizeof(int)` the overload `std::abs(long int)` will still be picked. Therefore we must ensure that we assert the correct return type. This update fixes the current issue, but I don't think it is a perfect solution. For example if `sizeof(short int) == sizeof(int)` it would still be upgraded to type `int` and the test would fail.


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

https://reviews.llvm.org/D57778

Files:
  libcxx/test/std/numerics/c.math/abs.pass.cpp


Index: libcxx/test/std/numerics/c.math/abs.pass.cpp
===================================================================
--- libcxx/test/std/numerics/c.math/abs.pass.cpp
+++ libcxx/test/std/numerics/c.math/abs.pass.cpp
@@ -16,7 +16,7 @@
 template<class T>
 struct correct_size_int
 {
-    typedef typename std::conditional<sizeof(T) <= sizeof(int), int, T>::type type;
+    typedef typename std::conditional<sizeof(T) < sizeof(int), int, T>::type type;
 };
 
 template <class Source, class Result>


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D57778.216216.patch
Type: text/x-patch
Size: 497 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libcxx-commits/attachments/20190820/287514c3/attachment.bin>


More information about the libcxx-commits mailing list