From e968256406fd7898d7fde880e31e54b041d32a7e Mon Sep 17 00:00:00 2001 From: Abseil Team Date: Thu, 7 Mar 2024 12:13:34 -0800 Subject: Work around an implicit conversion signedness compiler warning Addition and subtraction operators std::array::iterator are defined only for ptrdiff_t, which is signed, instead of size_t, which is unsigned. Therefore, adding the index variable to ar.begin() will trigger -Wsign-conversion if std::array::iterator is not a raw pointer because the index variable will be implicitly converted from size_t (an unsigned type) to ptrdiff_t (a signed type). To fix this, we explicitly static_cast index to a ptrdiff_t. PiperOrigin-RevId: 613662928 Change-Id: I5e06c2261d7b8f167fae7bb6acece076257f8579 --- absl/strings/internal/str_split_internal.h | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'absl/strings/internal') diff --git a/absl/strings/internal/str_split_internal.h b/absl/strings/internal/str_split_internal.h index 081ad85a..11ea96f2 100644 --- a/absl/strings/internal/str_split_internal.h +++ b/absl/strings/internal/str_split_internal.h @@ -30,6 +30,7 @@ #define ABSL_STRINGS_INTERNAL_STR_SPLIT_INTERNAL_H_ #include +#include #include #include #include @@ -402,7 +403,10 @@ class Splitter { ar[index].size = it->size(); ++it; } while (++index != ar.size() && !it.at_end()); - v.insert(v.end(), ar.begin(), ar.begin() + index); + // We static_cast index to a signed type to work around overzealous + // compiler warnings about signedness. + v.insert(v.end(), ar.begin(), + ar.begin() + static_cast(index)); } return v; } -- cgit v1.2.3