diff options
author | Abseil Team <absl-team@google.com> | 2024-03-07 12:13:34 -0800 |
---|---|---|
committer | Copybara-Service <copybara-worker@google.com> | 2024-03-07 12:14:29 -0800 |
commit | e968256406fd7898d7fde880e31e54b041d32a7e (patch) | |
tree | c4d62cc99f3184c89b2227af78480381f19dff05 /absl/strings/internal | |
parent | d03f54ef130a3070965618eae4e0e8f97cdd4ca6 (diff) |
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
Diffstat (limited to 'absl/strings/internal')
-rw-r--r-- | absl/strings/internal/str_split_internal.h | 6 |
1 files changed, 5 insertions, 1 deletions
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 <array> +#include <cstddef> #include <initializer_list> #include <iterator> #include <tuple> @@ -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<ptrdiff_t>(index)); } return v; } |