summaryrefslogtreecommitdiff
path: root/absl/strings/numbers.h
diff options
context:
space:
mode:
authorGravatar Abseil Team <absl-team@google.com>2021-11-10 13:26:07 -0800
committerGravatar rogeeff <rogeeff@google.com>2021-11-11 03:09:50 -0500
commitf2dbd918d8d08529800eb72f23bd2829f92104a4 (patch)
treece812cd1f58083ef63d8a5d1185a9bb15667aabc /absl/strings/numbers.h
parent732b5580f089101ce4b8cdff55bb6461c59a6720 (diff)
Export of internal Abseil changes
-- 317c7bd0caa12fa0a4dc65dc9c8e645211f85872 by Abseil Team <absl-team@google.com>: Elide the Emscripten JS-based stack trace and symbolization functions when building in Standalone Mode. Users will need to set `-DSTANDALONE_WASM=1` in some toolchain(s). PiperOrigin-RevId: 408961649 -- 92ba3ab1ef3edee4b7fb9e151f2061661e7beb0a by Derek Mauro <dmauro@google.com>: Suppress MSVC warning "C4127: conditional expression is constant" Fixes #1004 PiperOrigin-RevId: 408920356 GitOrigin-RevId: 317c7bd0caa12fa0a4dc65dc9c8e645211f85872 Change-Id: Ieca0a9e263874ba5bd93110dc437c56bc59ad5a7
Diffstat (limited to 'absl/strings/numbers.h')
-rw-r--r--absl/strings/numbers.h30
1 files changed, 18 insertions, 12 deletions
diff --git a/absl/strings/numbers.h b/absl/strings/numbers.h
index 4ae07c2d..e977fc67 100644
--- a/absl/strings/numbers.h
+++ b/absl/strings/numbers.h
@@ -181,16 +181,19 @@ char* FastIntToBuffer(int_type i, char* buffer) {
// TODO(jorg): This signed-ness check is used because it works correctly
// with enums, and it also serves to check that int_type is not a pointer.
// If one day something like std::is_signed<enum E> works, switch to it.
- if (static_cast<int_type>(1) - 2 < 0) { // Signed
- if (sizeof(i) > 32 / 8) { // 33-bit to 64-bit
+ // These conditions are constexpr bools to suppress MSVC warning C4127.
+ constexpr bool kIsSigned = static_cast<int_type>(1) - 2 < 0;
+ constexpr bool kUse64Bit = sizeof(i) > 32 / 8;
+ if (kIsSigned) {
+ if (kUse64Bit) {
return FastIntToBuffer(static_cast<int64_t>(i), buffer);
- } else { // 32-bit or less
+ } else {
return FastIntToBuffer(static_cast<int32_t>(i), buffer);
}
- } else { // Unsigned
- if (sizeof(i) > 32 / 8) { // 33-bit to 64-bit
+ } else {
+ if (kUse64Bit) {
return FastIntToBuffer(static_cast<uint64_t>(i), buffer);
- } else { // 32-bit or less
+ } else {
return FastIntToBuffer(static_cast<uint32_t>(i), buffer);
}
}
@@ -209,22 +212,25 @@ ABSL_MUST_USE_RESULT bool safe_strtoi_base(absl::string_view s, int_type* out,
// TODO(jorg): This signed-ness check is used because it works correctly
// with enums, and it also serves to check that int_type is not a pointer.
// If one day something like std::is_signed<enum E> works, switch to it.
- if (static_cast<int_type>(1) - 2 < 0) { // Signed
- if (sizeof(*out) == 64 / 8) { // 64-bit
+ // These conditions are constexpr bools to suppress MSVC warning C4127.
+ constexpr bool kIsSigned = static_cast<int_type>(1) - 2 < 0;
+ constexpr bool kUse64Bit = sizeof(*out) == 64 / 8;
+ if (kIsSigned) {
+ if (kUse64Bit) {
int64_t val;
parsed = numbers_internal::safe_strto64_base(s, &val, base);
*out = static_cast<int_type>(val);
- } else { // 32-bit
+ } else {
int32_t val;
parsed = numbers_internal::safe_strto32_base(s, &val, base);
*out = static_cast<int_type>(val);
}
- } else { // Unsigned
- if (sizeof(*out) == 64 / 8) { // 64-bit
+ } else {
+ if (kUse64Bit) {
uint64_t val;
parsed = numbers_internal::safe_strtou64_base(s, &val, base);
*out = static_cast<int_type>(val);
- } else { // 32-bit
+ } else {
uint32_t val;
parsed = numbers_internal::safe_strtou32_base(s, &val, base);
*out = static_cast<int_type>(val);