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 fowles committed May 7, 2023
1 parent 28c9905 commit fe1277f
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 @@ -494,7 +494,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 @@ -775,7 +775,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 fe1277f

Please sign in to comment.