diff --git a/absl/base/config.h b/absl/base/config.h index a38c582..e4518ca 100644 --- a/absl/base/config.h +++ b/absl/base/config.h
@@ -755,7 +755,7 @@ #ifdef ABSL_INTERNAL_HAS_CXA_DEMANGLE #error ABSL_INTERNAL_HAS_CXA_DEMANGLE cannot be directly set #elif defined(OS_ANDROID) && (defined(__i386__) || defined(__x86_64__)) -#define ABSL_INTERNAL_HAS_CXA_DEMANGLE 0 +#undef ABSL_INTERNAL_HAS_CXA_DEMANGLE #elif defined(__GNUC__) #define ABSL_INTERNAL_HAS_CXA_DEMANGLE 1 #elif defined(__clang__) && !defined(_MSC_VER)
diff --git a/absl/container/btree_test.cc b/absl/container/btree_test.cc index 1d2c2a6..a6438f5 100644 --- a/absl/container/btree_test.cc +++ b/absl/container/btree_test.cc
@@ -2048,7 +2048,10 @@ TEST(Btree, ExtractDoesntCauseExtraMoves) { #ifdef _MSC_VER - GTEST_SKIP() << "This test fails on MSVC."; + // This conditional is to avoid an unreachable code warning. + if (_MSC_VER > 0) { + GTEST_SKIP() << "This test fails on MSVC."; + } #endif using Set = absl::btree_set<MovableOnlyInstance>;
diff --git a/absl/copts/GENERATED_AbseilCopts.cmake b/absl/copts/GENERATED_AbseilCopts.cmake index 32b97fc..b08c34c 100644 --- a/absl/copts/GENERATED_AbseilCopts.cmake +++ b/absl/copts/GENERATED_AbseilCopts.cmake
@@ -10,6 +10,46 @@ "/D_CRT_SECURE_NO_WARNINGS" "/D_SCL_SECURE_NO_WARNINGS" "/D_ENABLE_EXTENDED_ALIGNED_STORAGE" + "-Wmost" + "-Wextra" + "-Wc++98-compat-extra-semi" + "-Wcast-qual" + "-Wconversion" + "-Wdeprecated-pragma" + "-Wfloat-overflow-conversion" + "-Wfloat-zero-conversion" + "-Wfor-loop-analysis" + "-Wformat-security" + "-Wgnu-redeclared-enum" + "-Winfinite-recursion" + "-Winvalid-constexpr" + "-Wliteral-conversion" + "-Wmissing-declarations" + "-Wnullability-completeness" + "-Woverlength-strings" + "-Wpointer-arith" + "-Wself-assign" + "-Wshadow-all" + "-Wshorten-64-to-32" + "-Wsign-conversion" + "-Wstring-conversion" + "-Wtautological-overlap-compare" + "-Wtautological-unsigned-zero-compare" + "-Wthread-safety" + "-Wundef" + "-Wuninitialized" + "-Wunreachable-code" + "-Wunused-comparison" + "-Wunused-local-typedefs" + "-Wunused-result" + "-Wvla" + "-Wwrite-strings" + "-Wno-float-conversion" + "-Wno-implicit-float-conversion" + "-Wno-implicit-int-float-conversion" + "-Wno-unknown-warning-option" + "-Wno-unused-command-line-argument" + "-DNOMINMAX" ) list(APPEND ABSL_CLANG_CL_TEST_FLAGS @@ -19,6 +59,43 @@ "/D_CRT_SECURE_NO_WARNINGS" "/D_SCL_SECURE_NO_WARNINGS" "/D_ENABLE_EXTENDED_ALIGNED_STORAGE" + "-Wmost" + "-Wextra" + "-Wc++98-compat-extra-semi" + "-Wcast-qual" + "-Wconversion" + "-Wdeprecated-pragma" + "-Wfloat-overflow-conversion" + "-Wfloat-zero-conversion" + "-Wfor-loop-analysis" + "-Wformat-security" + "-Wgnu-redeclared-enum" + "-Winfinite-recursion" + "-Winvalid-constexpr" + "-Wliteral-conversion" + "-Wmissing-declarations" + "-Woverlength-strings" + "-Wpointer-arith" + "-Wself-assign" + "-Wshadow-all" + "-Wstring-conversion" + "-Wtautological-overlap-compare" + "-Wtautological-unsigned-zero-compare" + "-Wthread-safety" + "-Wundef" + "-Wuninitialized" + "-Wunreachable-code" + "-Wunused-comparison" + "-Wunused-local-typedefs" + "-Wunused-result" + "-Wvla" + "-Wwrite-strings" + "-Wno-float-conversion" + "-Wno-implicit-float-conversion" + "-Wno-implicit-int-float-conversion" + "-Wno-unknown-warning-option" + "-Wno-unused-command-line-argument" + "-DNOMINMAX" "-Wno-deprecated-declarations" "-Wno-implicit-int-conversion" "-Wno-missing-prototypes" @@ -84,6 +161,7 @@ list(APPEND ABSL_LLVM_FLAGS "-Wall" + "-Wmost" "-Wextra" "-Wc++98-compat-extra-semi" "-Wcast-qual" @@ -127,6 +205,7 @@ list(APPEND ABSL_LLVM_TEST_FLAGS "-Wall" + "-Wmost" "-Wextra" "-Wc++98-compat-extra-semi" "-Wcast-qual"
diff --git a/absl/copts/GENERATED_copts.bzl b/absl/copts/GENERATED_copts.bzl index 8d72190..8c1d7a0 100644 --- a/absl/copts/GENERATED_copts.bzl +++ b/absl/copts/GENERATED_copts.bzl
@@ -11,6 +11,46 @@ "/D_CRT_SECURE_NO_WARNINGS", "/D_SCL_SECURE_NO_WARNINGS", "/D_ENABLE_EXTENDED_ALIGNED_STORAGE", + "-Wmost", + "-Wextra", + "-Wc++98-compat-extra-semi", + "-Wcast-qual", + "-Wconversion", + "-Wdeprecated-pragma", + "-Wfloat-overflow-conversion", + "-Wfloat-zero-conversion", + "-Wfor-loop-analysis", + "-Wformat-security", + "-Wgnu-redeclared-enum", + "-Winfinite-recursion", + "-Winvalid-constexpr", + "-Wliteral-conversion", + "-Wmissing-declarations", + "-Wnullability-completeness", + "-Woverlength-strings", + "-Wpointer-arith", + "-Wself-assign", + "-Wshadow-all", + "-Wshorten-64-to-32", + "-Wsign-conversion", + "-Wstring-conversion", + "-Wtautological-overlap-compare", + "-Wtautological-unsigned-zero-compare", + "-Wthread-safety", + "-Wundef", + "-Wuninitialized", + "-Wunreachable-code", + "-Wunused-comparison", + "-Wunused-local-typedefs", + "-Wunused-result", + "-Wvla", + "-Wwrite-strings", + "-Wno-float-conversion", + "-Wno-implicit-float-conversion", + "-Wno-implicit-int-float-conversion", + "-Wno-unknown-warning-option", + "-Wno-unused-command-line-argument", + "-DNOMINMAX", ] ABSL_CLANG_CL_TEST_FLAGS = [ @@ -20,6 +60,43 @@ "/D_CRT_SECURE_NO_WARNINGS", "/D_SCL_SECURE_NO_WARNINGS", "/D_ENABLE_EXTENDED_ALIGNED_STORAGE", + "-Wmost", + "-Wextra", + "-Wc++98-compat-extra-semi", + "-Wcast-qual", + "-Wconversion", + "-Wdeprecated-pragma", + "-Wfloat-overflow-conversion", + "-Wfloat-zero-conversion", + "-Wfor-loop-analysis", + "-Wformat-security", + "-Wgnu-redeclared-enum", + "-Winfinite-recursion", + "-Winvalid-constexpr", + "-Wliteral-conversion", + "-Wmissing-declarations", + "-Woverlength-strings", + "-Wpointer-arith", + "-Wself-assign", + "-Wshadow-all", + "-Wstring-conversion", + "-Wtautological-overlap-compare", + "-Wtautological-unsigned-zero-compare", + "-Wthread-safety", + "-Wundef", + "-Wuninitialized", + "-Wunreachable-code", + "-Wunused-comparison", + "-Wunused-local-typedefs", + "-Wunused-result", + "-Wvla", + "-Wwrite-strings", + "-Wno-float-conversion", + "-Wno-implicit-float-conversion", + "-Wno-implicit-int-float-conversion", + "-Wno-unknown-warning-option", + "-Wno-unused-command-line-argument", + "-DNOMINMAX", "-Wno-deprecated-declarations", "-Wno-implicit-int-conversion", "-Wno-missing-prototypes", @@ -85,6 +162,7 @@ ABSL_LLVM_FLAGS = [ "-Wall", + "-Wmost", "-Wextra", "-Wc++98-compat-extra-semi", "-Wcast-qual", @@ -128,6 +206,7 @@ ABSL_LLVM_TEST_FLAGS = [ "-Wall", + "-Wmost", "-Wextra", "-Wc++98-compat-extra-semi", "-Wcast-qual",
diff --git a/absl/copts/copts.py b/absl/copts/copts.py index e6c4385..c1d1f4a 100644 --- a/absl/copts/copts.py +++ b/absl/copts/copts.py
@@ -41,8 +41,13 @@ "-Wno-unused-private-field", ] -ABSL_LLVM_FLAGS = [ - "-Wall", +# https://github.com/llvm/llvm-project/issues/102982 +# A list of LLVM base flags without -Wall. This is because clang-cl +# translates -Wall to -Weverything on Windows, mimicking MSVCs +# behavior. On most other platforms, -Wall is just a set of very good +# default flags. +ABSL_LLVM_BASE_FLAGS = [ + "-Wmost", "-Wextra", "-Wc++98-compat-extra-semi", "-Wcast-qual", @@ -89,6 +94,8 @@ "-DNOMINMAX", ] +ABSL_LLVM_FLAGS = ["-Wall"] + ABSL_LLVM_BASE_FLAGS + ABSL_LLVM_TEST_ADDITIONAL_FLAGS = [ "-Wno-deprecated-declarations", "-Wno-implicit-int-conversion", @@ -164,9 +171,15 @@ "ABSL_LLVM_TEST_FLAGS": GccStyleFilterAndCombine( ABSL_LLVM_FLAGS, ABSL_LLVM_TEST_ADDITIONAL_FLAGS ), - "ABSL_CLANG_CL_FLAGS": MSVC_BIG_WARNING_FLAGS + MSVC_DEFINES, + "ABSL_CLANG_CL_FLAGS": ( + MSVC_BIG_WARNING_FLAGS + MSVC_DEFINES + ABSL_LLVM_BASE_FLAGS + ), "ABSL_CLANG_CL_TEST_FLAGS": ( - MSVC_BIG_WARNING_FLAGS + MSVC_DEFINES + ABSL_LLVM_TEST_ADDITIONAL_FLAGS + MSVC_BIG_WARNING_FLAGS + + MSVC_DEFINES + + GccStyleFilterAndCombine( + ABSL_LLVM_BASE_FLAGS, ABSL_LLVM_TEST_ADDITIONAL_FLAGS + ) ), "ABSL_MSVC_FLAGS": ( MSVC_BIG_WARNING_FLAGS + MSVC_WARNING_FLAGS + MSVC_DEFINES
diff --git a/absl/debugging/internal/demangle.cc b/absl/debugging/internal/demangle.cc index 5f62ebb..a8d7511 100644 --- a/absl/debugging/internal/demangle.cc +++ b/absl/debugging/internal/demangle.cc
@@ -28,7 +28,7 @@ #include "absl/base/config.h" #include "absl/debugging/internal/demangle_rust.h" -#if ABSL_INTERNAL_HAS_CXA_DEMANGLE +#ifdef ABSL_INTERNAL_HAS_CXA_DEMANGLE #include <cxxabi.h> #endif @@ -2941,7 +2941,7 @@ std::string out; int status = 0; char* demangled = nullptr; -#if ABSL_INTERNAL_HAS_CXA_DEMANGLE +#ifdef ABSL_INTERNAL_HAS_CXA_DEMANGLE demangled = abi::__cxa_demangle(mangled, nullptr, nullptr, &status); #endif if (status == 0 && demangled != nullptr) {
diff --git a/absl/debugging/stacktrace_test.cc b/absl/debugging/stacktrace_test.cc index c1d3d84..177db64 100644 --- a/absl/debugging/stacktrace_test.cc +++ b/absl/debugging/stacktrace_test.cc
@@ -94,15 +94,23 @@ // This is a separate function to avoid inlining. ABSL_ATTRIBUTE_NOINLINE static void FixupNoFixupEquivalenceNoInline() { #if !ABSL_HAVE_ATTRIBUTE_WEAK - GTEST_SKIP() << "Need weak symbol support"; -#endif -#if defined(__riscv) - GTEST_SKIP() << "Skipping test on RISC-V due to pre-existing failure"; -#endif -#if defined(_WIN32) + const char* kSkipReason = "Need weak symbol support"; +#elif defined(__riscv) + const char* kSkipReason = + "Skipping test on RISC-V due to pre-existing failure"; +#elif defined(_WIN32) // TODO(b/434184677): Add support for fixups on Windows if needed - GTEST_SKIP() << "Skipping test on Windows due to lack of support for fixups"; + const char* kSkipReason = + "Skipping test on Windows due to lack of support for fixups"; +#else + const char* kSkipReason = nullptr; #endif + + // This conditional is to avoid an unreachable code warning. + if (kSkipReason != nullptr) { + GTEST_SKIP() << kSkipReason; + } + bool can_rely_on_frame_pointers = false; if (!can_rely_on_frame_pointers) { GTEST_SKIP() << "Frame pointers are required, but not guaranteed in OSS"; @@ -233,13 +241,20 @@ TEST(StackTrace, FixupLowStackUsage) { #if !ABSL_HAVE_ATTRIBUTE_WEAK - GTEST_SKIP() << "Skipping test on MSVC due to weak symbols"; -#endif -#if defined(_WIN32) + const char* kSkipReason = "Skipping test on MSVC due to weak symbols"; +#elif defined(_WIN32) // TODO(b/434184677): Add support for fixups on Windows if needed - GTEST_SKIP() << "Skipping test on Windows due to lack of support for fixups"; + const char* kSkipReason = + "Skipping test on Windows due to lack of support for fixups"; +#else + const char* kSkipReason = nullptr; #endif + // This conditional is to avoid an unreachable code warning. + if (kSkipReason != nullptr) { + GTEST_SKIP() << kSkipReason; + } + const Cleanup restore_state([enable_fixup = g_enable_fixup, fixup_calls = g_fixup_calls, should_fixup_calls = g_should_fixup_calls]() { @@ -276,13 +291,20 @@ TEST(StackTrace, CustomUnwinderPerformsFixup) { #if !ABSL_HAVE_ATTRIBUTE_WEAK - GTEST_SKIP() << "Need weak symbol support"; -#endif -#if defined(_WIN32) + const char* kSkipReason = "Need weak symbol support"; +#elif defined(_WIN32) // TODO(b/434184677): Add support for fixups on Windows if needed - GTEST_SKIP() << "Skipping test on Windows due to lack of support for fixups"; + const char* kSkipReason = + "Skipping test on Windows due to lack of support for fixups"; +#else + const char* kSkipReason = nullptr; #endif + // This conditional is to avoid an unreachable code warning. + if (kSkipReason != nullptr) { + GTEST_SKIP() << kSkipReason; + } + constexpr int kSkip = 1; // Skip our own frame, whose return PCs won't match constexpr auto kStackCount = 1;
diff --git a/absl/functional/internal/any_invocable.h b/absl/functional/internal/any_invocable.h index a696fdd..597c210 100644 --- a/absl/functional/internal/any_invocable.h +++ b/absl/functional/internal/any_invocable.h
@@ -159,10 +159,18 @@ // A discriminator when calling the "manager" function that describes operation // type-erased operation should be invoked. // +// "dispose" specifies that the manager should perform a destroy. +// // "relocate_from_to" specifies that the manager should perform a move. // -// "dispose" specifies that the manager should perform a destroy. -enum class FunctionToCall : bool { relocate_from_to, dispose }; +// "relocate_from_to_and_query_rust" is identical to "relocate_from_to" for C++ +// managers, but instructs Rust managers to perform a special operation that +// can be detected by the caller. +enum class FunctionToCall : unsigned char { + dispose, + relocate_from_to, + relocate_from_to_and_query_rust, +}; // The portion of `AnyInvocable` state that contains either a pointer to the // target object or the object itself in local storage @@ -243,6 +251,7 @@ switch (operation) { case FunctionToCall::relocate_from_to: + case FunctionToCall::relocate_from_to_and_query_rust: // NOTE: Requires that the left-hand operand is already empty. ::new (static_cast<void*>(&to->storage)) T(std::move(from_object)); ABSL_FALLTHROUGH_INTENDED; @@ -277,6 +286,7 @@ TypeErasedState* const to) noexcept { switch (operation) { case FunctionToCall::relocate_from_to: + case FunctionToCall::relocate_from_to_and_query_rust: // NOTE: Requires that the left-hand operand is already empty. to->remote = from->remote; return; @@ -303,6 +313,7 @@ switch (operation) { case FunctionToCall::relocate_from_to: + case FunctionToCall::relocate_from_to_and_query_rust: // NOTE: Requires that the left-hand operand is already empty. to->remote.target = from->remote.target; return;
diff --git a/absl/hash/internal/low_level_hash_test.cc b/absl/hash/internal/low_level_hash_test.cc index c8573b1..b4fe872 100644 --- a/absl/hash/internal/low_level_hash_test.cc +++ b/absl/hash/internal/low_level_hash_test.cc
@@ -361,9 +361,13 @@ #if defined(ABSL_IS_BIG_ENDIAN) || !defined(ABSL_HAVE_INTRINSIC_INT128) || \ UINTPTR_MAX != UINT64_MAX constexpr uint64_t kGolden[kNumGoldenOutputs] = {}; - GTEST_SKIP() - << "We only maintain golden data for little endian 64 bit systems with " - "128 bit intristics."; + // This conditional is to avoid an unreachable code warning. + bool skip = true; + if (skip) { + GTEST_SKIP() + << "We only maintain golden data for little endian 64 bit systems with " + "128 bit intristics."; + } #elif defined(__SSE4_2__) && defined(__AES__) constexpr uint64_t kGolden[kNumGoldenOutputs] = { 0xd6bdb2c9ba5e55f2, 0xffd3e23d4115a8ae, 0x2c3218ef486127de,
diff --git a/absl/log/internal/vlog_config.cc b/absl/log/internal/vlog_config.cc index 97665a5..e9b4827 100644 --- a/absl/log/internal/vlog_config.cc +++ b/absl/log/internal/vlog_config.cc
@@ -45,13 +45,25 @@ namespace log_internal { namespace { -bool ModuleIsPath(absl::string_view module_pattern) { + #ifdef _WIN32 - return module_pattern.find_first_of("/\\") != module_pattern.npos; +constexpr char kPathSeparators[] = "/\\"; #else - return module_pattern.find('/') != module_pattern.npos; +constexpr char kPathSeparators[] = "/"; #endif + +bool ModuleIsPath(absl::string_view module_pattern) { + return module_pattern.find_first_of(kPathSeparators) != module_pattern.npos; } + +absl::string_view Basename(absl::string_view file) { + auto sep = file.find_last_of(kPathSeparators); + if (sep != file.npos) { + file.remove_prefix(sep + 1); + } + return file; +} + } // namespace bool VLogSite::SlowIsEnabled(int stale_v, int level) { @@ -129,21 +141,9 @@ // parsing flags). We can't allocate in `VLOG`, so we treat null as empty // here and press on. if (!infos || infos->empty()) return current_global_v; - // Get basename for file - absl::string_view basename = file; - { - const size_t sep = basename.rfind('/'); - if (sep != basename.npos) { - basename.remove_prefix(sep + 1); -#ifdef _WIN32 - } else { - const size_t sep = basename.rfind('\\'); - if (sep != basename.npos) basename.remove_prefix(sep + 1); -#endif - } - } - absl::string_view stem = file, stem_basename = basename; + absl::string_view stem = file; + absl::string_view stem_basename = Basename(stem); { const size_t sep = stem_basename.find('.'); if (sep != stem_basename.npos) {
diff --git a/absl/strings/internal/cord_rep_btree_test.cc b/absl/strings/internal/cord_rep_btree_test.cc index 840acf9..0950617 100644 --- a/absl/strings/internal/cord_rep_btree_test.cc +++ b/absl/strings/internal/cord_rep_btree_test.cc
@@ -1230,16 +1230,16 @@ if (api != 3) { // Does not contain contents - EXPECT_THAT(str, Not(AnyOf((HasSubstr("data = \"Hello world\""), - HasSubstr("data = \"Hello external\""), - HasSubstr("data = \"ello w\""), - HasSubstr("data = \"llo ext\""))))); + EXPECT_THAT(str, Not(AnyOf(HasSubstr("data = \"Hello world\""), + HasSubstr("data = \"Hello external\""), + HasSubstr("data = \"ello w\""), + HasSubstr("data = \"llo ext\"")))); } else { // Contains contents - EXPECT_THAT(str, AllOf((HasSubstr("data = \"Hello world\""), - HasSubstr("data = \"Hello external\""), - HasSubstr("data = \"ello w\""), - HasSubstr("data = \"llo ext\"")))); + EXPECT_THAT(str, AllOf(HasSubstr("data = \"Hello world\""), + HasSubstr("data = \"Hello external\""), + HasSubstr("data = \"ello w\""), + HasSubstr("data = \"llo ext\""))); } }
diff --git a/absl/strings/string_view.h b/absl/strings/string_view.h index 3176657..358570e 100644 --- a/absl/strings/string_view.h +++ b/absl/strings/string_view.h
@@ -58,6 +58,15 @@ #else // ABSL_USES_STD_STRING_VIEW +#if ABSL_HAVE_ATTRIBUTE(diagnose_if) +#define ABSL_INTERNAL_DIAGNOSE_IF_NULLPTR(x) \ + __attribute__((diagnose_if( \ + x == nullptr, \ + "null passed to a callee that requires a non-null argument", "error"))) +#else +#define ABSL_INTERNAL_DIAGNOSE_IF_NULLPTR(x) +#endif + #if ABSL_HAVE_BUILTIN(__builtin_memcmp) || \ (defined(__GNUC__) && !defined(__clang__)) || \ (defined(_MSC_VER) && _MSC_VER >= 1928) @@ -225,7 +234,7 @@ // instead (see below). // The length check is skipped since it is unnecessary and causes code bloat. constexpr string_view( // NOLINT(runtime/explicit) - const char* absl_nonnull str) + const char* absl_nonnull str) ABSL_INTERNAL_DIAGNOSE_IF_NULLPTR(str) : ptr_(str), length_(str ? StrlenInternal(str) : 0) { ABSL_HARDENING_ASSERT(str != nullptr); } @@ -779,6 +788,7 @@ ABSL_NAMESPACE_END } // namespace absl +#undef ABSL_INTERNAL_DIAGNOSE_IF_NULLPTR #undef ABSL_INTERNAL_STRING_VIEW_MEMCMP #endif // ABSL_USES_STD_STRING_VIEW
diff --git a/absl/time/internal/cctz/src/time_zone_format.cc b/absl/time/internal/cctz/src/time_zone_format.cc index f739e02..5b80c80 100644 --- a/absl/time/internal/cctz/src/time_zone_format.cc +++ b/absl/time/internal/cctz/src/time_zone_format.cc
@@ -13,12 +13,14 @@ // limitations under the License. #if !defined(HAS_STRPTIME) -#if !defined(_MSC_VER) && !defined(__MINGW32__) && !defined(__VXWORKS__) +#if defined(_MSC_VER) || defined(__MINGW32__) || defined(__VXWORKS__) +#define HAS_STRPTIME 0 +#else #define HAS_STRPTIME 1 // Assume everyone else has strptime(). #endif #endif -#if defined(HAS_STRPTIME) && HAS_STRPTIME +#if HAS_STRPTIME #if !defined(_XOPEN_SOURCE) && !defined(__FreeBSD__) && !defined(__OpenBSD__) #define _XOPEN_SOURCE 500 // Exposes definitions for SUSv2 (UNIX 98). #endif
diff --git a/absl/time/internal/cctz/src/time_zone_name_win.cc b/absl/time/internal/cctz/src/time_zone_name_win.cc index c3351cf..2b8724d 100644 --- a/absl/time/internal/cctz/src/time_zone_name_win.cc +++ b/absl/time/internal/cctz/src/time_zone_name_win.cc
@@ -23,6 +23,7 @@ #include <algorithm> #include <atomic> +#include <cstddef> #include <cstdint> #include <limits> #include <string> @@ -135,15 +136,14 @@ } const int chars_len = static_cast<int>(size); std::string result; - std::int32_t len = std::max<std::int32_t>( - static_cast<std::int32_t>(std::min<size_t>( - result.capacity(), std::numeric_limits<std::int32_t>::max())), - 1); + std::size_t len = std::max<std::size_t>( + std::min<size_t>(result.capacity(), std::numeric_limits<int>::max()), 1); do { result.resize(len); // TODO: Switch to std::string::data() when we require C++17 or higher. - len = ::WideCharToMultiByte(CP_UTF8, WC_ERR_INVALID_CHARS, ptr, chars_len, - &result[0], len, nullptr, nullptr); + len = static_cast<std::size_t>(::WideCharToMultiByte( + CP_UTF8, WC_ERR_INVALID_CHARS, ptr, chars_len, &result[0], + static_cast<int>(len), nullptr, nullptr)); } while (len > result.size()); result.resize(len); return result; @@ -163,15 +163,14 @@ } std::wstring result; - std::int32_t len = std::max<std::int32_t>( - static_cast<std::int32_t>(std::min<size_t>( - result.capacity(), std::numeric_limits<std::int32_t>::max())), - 1); + std::size_t len = std::max<std::size_t>( + std::min<size_t>(result.capacity(), std::numeric_limits<int>::max()), 1); for (;;) { UErrorCode status = U_ZERO_ERROR; result.resize(len); - len = getTimeZoneIDForWindowsID(info.TimeZoneKeyName, -1, nullptr, - &result[0], len, &status); + len = static_cast<std::size_t>( + getTimeZoneIDForWindowsID(info.TimeZoneKeyName, -1, nullptr, &result[0], + static_cast<int>(len), &status)); if (U_SUCCESS(status)) { return Utf16ToUtf8(result.data(), len); }