Removes msvc warning in map (#17013)
Hi,
We get a compiler warning in MSVC that a signed/unsigned comparison is executed.
The warning is at around line 1073 in src/google/protobuf/map.h
```cpp
ABSL_DCHECK_GE(new_num_buckets, kMinTableSize); // <-- signed/unsigned comparison
const auto old_table = table_;
const map_index_t old_table_size = num_buckets_;
num_buckets_ = new_num_buckets;
```
This is due to `kMinTableSize` is a enum value. Probably a C++98 way to enforce constexpr.
This PR changes `kMinTableSize` to be a constexpr unsigned `map_index_t` and removes the casts instead of fixing the warning with a cast at ne 1073.
It seems like `kMinTableSize` is correlated with the `TableSize` of this class, which is map_index_t. Therefore the min value can at maximum the max value of map_index_t. And the min value of `kMinTableSize` can also not be negative, as this makes no sense.
It is also nicer to have fewer casts.
Closes #17013
COPYBARA_INTEGRATE_REVIEW=https://github.com/protocolbuffers/protobuf/pull/17013 from TinyTinni:removes-msvc-warning-map 4f954e8c9b
PiperOrigin-RevId: 644207177
pull/17170/head
parent
41514865eb
commit
9f6a8bd1fa
1 changed files with 3 additions and 5 deletions
Loading…
Reference in new issue