Commit e9682564 by Abseil Team Committed by Copybara-Service

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
parent d03f54ef
......@@ -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;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment