Commit 3697fb05 authored by Jeff McGlynn's avatar Jeff McGlynn Committed by Facebook GitHub Bot

Fix build errors with -Wvla on Mac/iOS

Summary:
Conv.h's detail::digitsEnough was not decomposing to a constexpr on iOS/Mac toolchains, which resulted in the following call becoming a runtime VLA:

```
char buffer[detail::digitsEnough<unsigned __int128>() + 1];
```

Update to use `numeric_limits<>::digits10`, which allows this function to evaluate at compile-time on iOS/Mac.

Reviewed By: yfeldblum

Differential Revision: D20440659

fbshipit-source-id: d086e367eec0d3b2f35465525cb7406e746e6df7
parent 0dd89890
......@@ -329,7 +329,12 @@ namespace detail {
template <typename IntegerType>
constexpr unsigned int digitsEnough() {
return (unsigned int)(ceil(sizeof(IntegerType) * CHAR_BIT * M_LN2 / M_LN10));
// digits10 returns the number of decimal digits that this type can represent,
// not the number of characters required for the max value, so we need to add
// one. ex: char digits10 returns 2, because 256-999 cannot be represented,
// but we need 3.
auto const digits10 = std::numeric_limits<IntegerType>::digits10;
return static_cast<unsigned int>(digits10) + 1;
}
inline size_t
......
......@@ -215,9 +215,6 @@ void test128Bit2String() {
svalue = (Uint(1) << 127) - 1;
EXPECT_EQ(to<String>(svalue), "170141183460469231731687303715884105727");
// TODO: the following do not compile to<__int128> ...
#if 0
value = numeric_limits<Uint>::min();
EXPECT_EQ(to<Uint>(to<String>(value)), value);
value = numeric_limits<Uint>::max();
......@@ -227,7 +224,6 @@ void test128Bit2String() {
EXPECT_EQ(to<Sint>(to<String>(svalue)), svalue);
value = numeric_limits<Sint>::max();
EXPECT_EQ(to<Sint>(to<String>(svalue)), svalue);
#endif
}
#endif
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment