mirror of
https://github.com/fastfloat/fast_float.git
synced 2025-12-06 16:56:57 +08:00
Fix more Werrors
- Werror=conversion,char-subscripts
This commit is contained in:
parent
7a21a8d6d7
commit
624ba49434
@ -7,6 +7,7 @@
|
|||||||
#include <iterator>
|
#include <iterator>
|
||||||
#include <limits>
|
#include <limits>
|
||||||
#include <type_traits>
|
#include <type_traits>
|
||||||
|
#include <charconv>
|
||||||
|
|
||||||
#include "float_common.h"
|
#include "float_common.h"
|
||||||
|
|
||||||
@ -462,11 +463,6 @@ from_chars_result_t<UC> parse_int_string(UC const* p, UC const* pend, T& value,
|
|||||||
++p;
|
++p;
|
||||||
}
|
}
|
||||||
|
|
||||||
// skip leading zeros
|
|
||||||
while (p != pend && *p == UC('0')) {
|
|
||||||
++p;
|
|
||||||
}
|
|
||||||
|
|
||||||
UC const* const start_digits = p;
|
UC const* const start_digits = p;
|
||||||
|
|
||||||
uint64_t i = 0;
|
uint64_t i = 0;
|
||||||
@ -512,10 +508,9 @@ from_chars_result_t<UC> parse_int_string(UC const* p, UC const* pend, T& value,
|
|||||||
if (negative) {
|
if (negative) {
|
||||||
// this weird workaround is required because:
|
// this weird workaround is required because:
|
||||||
// - converting unsigned to signed when its value is greater than signed max is UB pre-C++23.
|
// - converting unsigned to signed when its value is greater than signed max is UB pre-C++23.
|
||||||
// - reinterpret_cast<T>(~i + 1) would have worked, but it is not constexpr
|
// - reinterpret_casting (~i + 1) would work, but it is not constexpr
|
||||||
// this should be optimized away.
|
// this is always optimized into a neg instruction.
|
||||||
value = -std::numeric_limits<T>::max() -
|
value = T(-std::numeric_limits<T>::max() - T(i - std::numeric_limits<T>::max()));
|
||||||
static_cast<T>(i - std::numeric_limits<T>::max());
|
|
||||||
}
|
}
|
||||||
else value = T(i);
|
else value = T(i);
|
||||||
|
|
||||||
|
|||||||
@ -741,7 +741,7 @@ constexpr uint64_t int_luts<T>::min_safe_u64[];
|
|||||||
|
|
||||||
template <typename UC>
|
template <typename UC>
|
||||||
fastfloat_really_inline
|
fastfloat_really_inline
|
||||||
constexpr uint8_t ch_to_digit(UC c) { return int_luts<>::chdigit[c]; }
|
constexpr uint8_t ch_to_digit(UC c) { return int_luts<>::chdigit[static_cast<unsigned char>(c)]; }
|
||||||
|
|
||||||
fastfloat_really_inline
|
fastfloat_really_inline
|
||||||
constexpr size_t max_digits_u64(int base) { return int_luts<>::maxdigits_u64[base - 2]; }
|
constexpr size_t max_digits_u64(int base) { return int_luts<>::maxdigits_u64[base - 2]; }
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user