[libcxx-commits] [PATCH] D57778: std::abs should not return double (2735)
Zoe Carver via Phabricator via libcxx-commits
libcxx-commits at lists.llvm.org
Sun Feb 10 12:17:51 PST 2019
zoecarver marked an inline comment as done.
zoecarver added inline comments.
================
Comment at: test/std/numerics/c.math/abs.pass.cpp:27
+
+ ASSERT_SAME_TYPE(decltype(std::abs(neg_val)), R);
+
----------------
zoecarver wrote:
> mclow.lists wrote:
> > mclow.lists wrote:
> > > 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.
> > In particular, we want to be sure that `std::abs(char)` returns `int`, not `char`, which can be promoted to an `int`.
> >
> I will play around with this a bit and see what works. Is there a template for integral promotion?
Do either of you know how to do something like this?
```
template <typename T, typename U>
struct upgrade_intergal
{
using type = typename std::conditional<sizeof(T) <= sizeof(U), U, upgrade_intergal<T, long U>>::type;
};
```
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D57778/new/
https://reviews.llvm.org/D57778
More information about the libcxx-commits
mailing list