Skip to content

Commit a1f6638

Browse files
committed
Fix -Wsign-compare and -Wundef warnings from clang on Windows
These warning were initially reported by Chromium, and I've managed to fix the Abseil testing configuration to find these warnings. Currently CCTZ doesn't test clang on Windows.
1 parent 27ca173 commit a1f6638

File tree

2 files changed

+13
-14
lines changed

2 files changed

+13
-14
lines changed

src/time_zone_format.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
#include <limits>
4040
#include <string>
4141
#include <vector>
42-
#if !HAS_STRPTIME
42+
#if !defined(HAS_STRPTIME)
4343
#include <iomanip>
4444
#include <sstream>
4545
#endif
@@ -52,7 +52,7 @@ namespace detail {
5252

5353
namespace {
5454

55-
#if !HAS_STRPTIME
55+
#if !defined(HAS_STRPTIME)
5656
// Build a strptime() using C++11's std::get_time().
5757
char* strptime(const char* s, const char* fmt, std::tm* tm) {
5858
std::istringstream input(s);

src/time_zone_name_win.cc

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
#include <algorithm>
2323
#include <atomic>
24+
#include <cstddef>
2425
#include <cstdint>
2526
#include <limits>
2627
#include <string>
@@ -129,15 +130,14 @@ std::string Utf16ToUtf8(const wchar_t* ptr, size_t size) {
129130
}
130131
const int chars_len = static_cast<int>(size);
131132
std::string result;
132-
std::int32_t len = std::max<std::int32_t>(
133-
static_cast<std::int32_t>(std::min<size_t>(
134-
result.capacity(), std::numeric_limits<std::int32_t>::max())),
135-
1);
133+
std::size_t len = std::max<std::size_t>(
134+
std::min<size_t>(result.capacity(), std::numeric_limits<int>::max()), 1);
136135
do {
137136
result.resize(len);
138137
// TODO: Switch to std::string::data() when we require C++17 or higher.
139-
len = ::WideCharToMultiByte(CP_UTF8, WC_ERR_INVALID_CHARS, ptr, chars_len,
140-
&result[0], len, nullptr, nullptr);
138+
len = static_cast<std::size_t>(::WideCharToMultiByte(
139+
CP_UTF8, WC_ERR_INVALID_CHARS, ptr, chars_len, &result[0],
140+
static_cast<int>(len), nullptr, nullptr));
141141
} while (len > result.size());
142142
result.resize(len);
143143
return result;
@@ -157,15 +157,14 @@ std::string GetWindowsLocalTimeZone() {
157157
}
158158

159159
std::wstring result;
160-
std::int32_t len = std::max<std::int32_t>(
161-
static_cast<std::int32_t>(std::min<size_t>(
162-
result.capacity(), std::numeric_limits<std::int32_t>::max())),
163-
1);
160+
std::size_t len = std::max<std::size_t>(
161+
std::min<size_t>(result.capacity(), std::numeric_limits<int>::max()), 1);
164162
for (;;) {
165163
UErrorCode status = U_ZERO_ERROR;
166164
result.resize(len);
167-
len = getTimeZoneIDForWindowsID(info.TimeZoneKeyName, -1, nullptr,
168-
&result[0], len, &status);
165+
len = static_cast<std::size_t>(
166+
getTimeZoneIDForWindowsID(info.TimeZoneKeyName, -1, nullptr, &result[0],
167+
static_cast<int>(len), &status));
169168
if (U_SUCCESS(status)) {
170169
return Utf16ToUtf8(result.data(), len);
171170
}

0 commit comments

Comments
 (0)