Skip to content

Commit

Permalink
fix: avoid warnings on Windows (#12701)
Browse files Browse the repository at this point in the history
On Wndows, `size_t` is 64-bits, and `int` is 32-bits. That makes conversions from `size_t` to `int` potentially lossy, and they generate warnings.  In this case an `int` variable was assigned to `size_t` and then passed to functions consuming `int`. Seems simpler to use `auto` and avoid these problems altogether.

Closes #12701

COPYBARA_INTEGRATE_REVIEW=#12701 from coryan:fix-warnings-repeated-field-warnings-in-msvc b1ec34d
PiperOrigin-RevId: 530134611
  • Loading branch information
coryan authored and copybara-github committed May 7, 2023
1 parent 5613ab0 commit f9108c2
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/google/protobuf/repeated_field.h
Original file line number Diff line number Diff line change
Expand Up @@ -505,7 +505,7 @@ template <typename Element>
inline RepeatedField<Element>::RepeatedField(const RepeatedField& rhs)
: current_size_(0), total_size_(0), arena_or_elements_(nullptr) {
StaticValidityCheck();
if (size_t size = rhs.current_size_) {
if (auto size = rhs.current_size_) {
Grow(0, size);
ExchangeCurrentSize(size);
UninitializedCopyN(rhs.elements(), size, unsafe_elements());
Expand Down Expand Up @@ -786,7 +786,7 @@ inline void RepeatedField<Element>::Clear() {
template <typename Element>
inline void RepeatedField<Element>::MergeFrom(const RepeatedField& rhs) {
ABSL_DCHECK_NE(&rhs, this);
if (size_t size = rhs.current_size_) {
if (auto size = rhs.current_size_) {
Reserve(current_size_ + size);
Element* dst = elements() + ExchangeCurrentSize(current_size_ + size);
UninitializedCopyN(rhs.elements(), size, dst);
Expand Down

0 comments on commit f9108c2

Please sign in to comment.