[caffe2] Fix shadowed variable warnings in `clang` (#80902)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/80902
This resolves build errors when using [-Werror,-Wshadow] under MSVC.
Manually rename method parameters to avoid shadowing instance members - suffix parameters w/ _ (would prefer to suffix members, but that's a bigger change).
Renaming parameters instead of member variables should reduce unintended side-effects.
Remove `pragma ignore("-Wshadow")` now that shadowed variables are resolved.
Test Plan:
Build as dependent library using clang asan for windows using MSVC.
Before: Build Failure when using warnings as errors (due to `-Wshadow` remaining enabled under MSVC with above mentioned shadowing warnings)
```
xplat/caffe2\c10/util/order_preserving_flat_hash_map.h(2036,22): error: declaration shadows a field of 'ska_ordered::fibonacci_hash_policy' [-Werror,-Wshadow]
void commit(int8_t shift) {
^
xplat/caffe2\c10/util/order_preserving_flat_hash_map.h(2044,10): note: previous declaration is here
int8_t shift = 63;
^
xplat/caffe2\c10/util/order_preserving_flat_hash_map.h(986,16): error: declaration shadows a field of 'sherwood_v3_table<T, FindKey, ArgumentHash, Hasher, ArgumentEqual, Equal, ArgumentAlloc, EntryAlloc>' [-Werror,-Wshadow]
uint64_t num_slots_minus_one,
^
xplat/caffe2\c10/util/order_preserving_flat_hash_map.h(2053,7): note: in instantiation of member function 'ska_ordered::detailv3::sherwood_v3_table<std::pair<c10::IValue, c10::IValue>, c10::IValue, c10::detail::DictKeyHash, ska_ordered::detailv3::KeyOrValueHasher<c10::IValue, std::pair<c10::IValue, c10::IValue>, c10::detail::DictKeyHash>, c10::detail::DictKeyEqualTo, ska_ordered::detailv3::KeyOrValueEquality<c10::IValue, std::pair<c10::IValue, c10::IValue>, c10::detail::DictKeyEqualTo>, std::allocator<std::pair<c10::IValue, c10::IValue> >, std::allocator<ska_ordered::detailv3::sherwood_v3_entry<std::pair<c10::IValue, c10::IValue> > > >::~sherwood_v3_table' requested here
class order_preserving_flat_hash_map
^
xplat/caffe2\c10/util/order_preserving_flat_hash_map.h(795,12): note: previous declaration is here
uint64_t num_slots_minus_one = 0;
^
xplat/caffe2\c10/util/order_preserving_flat_hash_map.h(987,14): error: declaration shadows a field of 'sherwood_v3_table<T, FindKey, ArgumentHash, Hasher, ArgumentEqual, Equal, ArgumentAlloc, EntryAlloc>' [-Werror,-Wshadow]
int8_t max_lookups) {
^
xplat/caffe2\c10/util/order_preserving_flat_hash_map.h(797,10): note: previous declaration is here
int8_t max_lookups = detailv3::min_lookups - 1;
^
xplat/caffe2\c10/util/order_preserving_flat_hash_map.h(830,45): error: declaration shadows a field of 'sherwood_v3_table<T, FindKey, ArgumentHash, Hasher, ArgumentEqual, Equal, ArgumentAlloc, EntryAlloc>' [-Werror,-Wshadow]
uint64_t num_buckets_for_reserve(uint64_t num_elements) const {
^
xplat/caffe2\c10/util/order_preserving_flat_hash_map.h(367,5): note: in instantiation of member function 'ska_ordered::detailv3::sherwood_v3_table<std::pair<c10::IValue, c10::IValue>, c10::IValue, c10::detail::DictKeyHash, ska_ordered::detailv3::KeyOrValueHasher<c10::IValue, std::pair<c10::IValue, c10::IValue>, c10::detail::DictKeyHash>, c10::detail::DictKeyEqualTo, ska_ordered::detailv3::KeyOrValueEquality<c10::IValue, std::pair<c10::IValue, c10::IValue>, c10::detail::DictKeyEqualTo>, std::allocator<std::pair<c10::IValue, c10::IValue> >, std::allocator<ska_ordered::detailv3::sherwood_v3_entry<std::pair<c10::IValue, c10::IValue> > > >::rehash_for_other_container' requested here
rehash_for_other_container(other);
^
xplat/caffe2\c10/util/order_preserving_flat_hash_map.h(358,9): note: in instantiation of member function 'ska_ordered::detailv3::sherwood_v3_table<std::pair<c10::IValue, c10::IValue>, c10::IValue, c10::detail::DictKeyHash, ska_ordered::detailv3::KeyOrValueHasher<c10::IValue, std::pair<c10::IValue, c10::IValue>, c10::detail::DictKeyHash>, c10::detail::DictKeyEqualTo, ska_ordered::detailv3::KeyOrValueEquality<c10::IValue, std::pair<c10::IValue, c10::IValue>, c10::detail::DictKeyEqualTo>, std::allocator<std::pair<c10::IValue, c10::IValue> >, std::allocator<ska_ordered::detailv3::sherwood_v3_entry<std::pair<c10::IValue, c10::IValue> > > >::sherwood_v3_table' requested here
: sherwood_v3_table(
^
xplat/caffe2\c10/util/order_preserving_flat_hash_map.h(2053,7): note: in instantiation of member function 'ska_ordered::detailv3::sherwood_v3_table<std::pair<c10::IValue, c10::IValue>, c10::IValue, c10::detail::DictKeyHash, ska_ordered::detailv3::KeyOrValueHasher<c10::IValue, std::pair<c10::IValue, c10::IValue>, c10::detail::DictKeyHash>, c10::detail::DictKeyEqualTo, ska_ordered::detailv3::KeyOrValueEquality<c10::IValue, std::pair<c10::IValue, c10::IValue>, c10::detail::DictKeyEqualTo>, std::allocator<std::pair<c10::IValue, c10::IValue> >, std::allocator<ska_ordered::detailv3::sherwood_v3_entry<std::pair<c10::IValue, c10::IValue> > > >::sherwood_v3_table' requested here
class order_preserving_flat_hash_map
^
xplat/caffe2\c10/util/intrusive_ptr.h(574,44): note: in instantiation of function template specialization 'c10::intrusive_ptr<c10::detail::DictImpl, c10::detail::intrusive_target_default_null_type<c10::detail::DictImpl> >::make<const ska_ordered::order_preserving_flat_hash_map<c10::IValue, c10::IValue, c10::detail::DictKeyHash, c10::detail::DictKeyEqualTo, std::allocator<std::pair<c10::IValue, c10::IValue> > > &, const c10::detail::DictImpl::DictElementTypes &>' requested here
return intrusive_ptr<TTarget, NullType>::make(std::forward<Args>(args)...);
^
xplat/caffe2/aten/src\ATen/core/Dict_inl.h(62,10): note: in instantiation of function template specialization 'c10::make_intrusive<c10::detail::DictImpl, c10::detail::intrusive_target_default_null_type<c10::detail::DictImpl>, const ska_ordered::order_preserving_flat_hash_map<c10::IValue, c10::IValue, c10::detail::DictKeyHash, c10::detail::DictKeyEqualTo, std::allocator<std::pair<c10::IValue, c10::IValue> > > &, const c10::detail::DictImpl::DictElementTypes &>' requested here
return make_intrusive<DictImpl>(dict, elementTypes);
^
xplat/caffe2\c10/util/order_preserving_flat_hash_map.h(799,12): note: previous declaration is here
uint64_t num_elements = 0;
^
5 errors generated.
```
After:
`BUILD SUCCEEDED`
Run dependent tests on applications with these changes - confirm all tests pass.
Reviewed By: malfet
Differential Revision: D30517712
Pull Request resolved: https://github.com/pytorch/pytorch/pull/80902
Approved by: https://github.com/malfet