Repository: pytorch
Issue: Compiler warnings tracking
Labels: triaged,module: build warnings

PyTorch's build outputs a bunch of compile warnings which make it hard to sift through build logs. This task lists them out and their status. Once all these are fixed we could/should turn on `-Werror` (and `-pedantic`) so things don't pop back up in the future. This list isn't comprehensive by any means, it's just what I collected on a Linux box with the default build options. See also #56085

## External

- [ ] onnx (this is fixed on master, need to update the submodule: #55889)

<details>

```
[2805/3029] Building CXX object caffe2/CMakeFiles/torch_cpu.dir/__/torch/csrc/jit/serialization/export.cpp.o
In file included from ../third_party/onnx/onnx/defs/shape_inference.h:4,
                 from ../third_party/onnx/onnx/defs/schema.h:24,
                 from ../third_party/onnx/onnx/checker.h:7,
                 from ../torch/csrc/jit/serialization/export.cpp:20:
../third_party/onnx/onnx/proto_utils.h: In instantiation of ‘bool onnx_torch::ParseProtoFromBytes(Proto*, const char*, size_t) [with Proto = onnx_torch::ModelProto; size_t = long unsigned int]’:
../torch/csrc/jit/serialization/export.cpp:952:77:   required from here
../third_party/onnx/onnx/proto_utils.h:34:34: warning: ‘void google::protobuf::io::CodedInputStream::SetTotalBytesLimit(int, int)’ is deprecated: Please use the single parameter version of SetTotalBytesLimit(). The second parameter is ignored. [-Wdeprecated-declarations]
   coded_stream.SetTotalBytesLimit((2048LL << 20) - 1, 512LL << 20);
   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from third_party/onnx/onnx/onnx_onnx_torch-ml.pb.h:23,
                 from third_party/onnx/onnx/onnx-ml.pb.h:2,
                 from ../third_party/onnx/onnx/onnx_pb.h:50,
                 from ../torch/csrc/jit/serialization/onnx.h:3,
                 from ../torch/csrc/jit/serialization/export.cpp:17:
../third_party/protobuf/src/google/protobuf/io/coded_stream.h:397:8: note: declared here
   void SetTotalBytesLimit(int total_bytes_limit, int) {
        ^~~~~~~~~~~~~~~~~~
```

</details>

- [x] pthreadpool (after https://github.com/Maratyszcza/pthreadpool/pull/15 lands, we can ignore the rest: #56291)

<details>

```
[959/3019] Building C object confu-deps/XNNPACK/CMakeFiles/XNNPACK.dir/src/f32-vscaleextexp/gen/avx512f-p5-scalef-x144.c.o
In file included from ../third_party/XNNPACK/include/xnnpack.h:15:0,
                 from ../third_party/XNNPACK/src/xnnpack/params.h:15,
                 from ../third_party/XNNPACK/src/xnnpack/vscaleextexp.h:11,
                 from ../third_party/XNNPACK/src/f32-vscaleextexp/gen/avx512f-p5-scalef-x144.c:16:
../third_party/pthreadpool/include/pthreadpool.h:183:2: warning: ‘pthreadpool_function_1d_t’ is deprecated [-Wdeprecated-declarations]
  pthreadpool_function_1d_t function,
  ^~~~~~~~~~~~~~~~~~~~~~~~~
../third_party/pthreadpool/include/pthreadpool.h:189:2: warning: ‘pthreadpool_function_1d_tiled_t’ is deprecated [-Wdeprecated-declarations]
  pthreadpool_function_1d_tiled_t function,
  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
../third_party/pthreadpool/include/pthreadpool.h:196:2: warning: ‘pthreadpool_function_2d_t’ is deprecated [-Wdeprecated-declarations]
  pthreadpool_function_2d_t function,
  ^~~~~~~~~~~~~~~~~~~~~~~~~
../third_party/pthreadpool/include/pthreadpool.h:203:2: warning: ‘pthreadpool_function_2d_tiled_t’ is deprecated [-Wdeprecated-declarations]
  pthreadpool_function_2d_tiled_t function,
  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
../third_party/pthreadpool/include/pthreadpool.h:212:2: warning: ‘pthreadpool_function_3d_tiled_t’ is deprecated [-Wdeprecated-declarations]
  pthreadpool_function_3d_tiled_t function,
  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
../third_party/pthreadpool/include/pthreadpool.h:223:2: warning: ‘pthreadpool_function_4d_tiled_t’ is deprecated [-Wdeprecated-declarations]
  pthreadpool_function_4d_tiled_t function,
  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
```

</details>

## Internal

- [x] `tensor_flatten.cpp` (fixed in #55956)

<details>

```
[2756/3029] Building CXX object caffe2/CMakeFiles/torch_cpu.dir/__/torch/csrc/utils/tensor_flatten.cpp.o
In file included from ../torch/csrc/utils/tensor_flatten.cpp:1:
../torch/csrc/utils/tensor_flatten.h: In member function ‘at::DeprecatedTypeProperties& torch::utils::TensorGroup::type()’:
../torch/csrc/utils/tensor_flatten.h:44:28: warning: ‘at::DeprecatedTypeProperties& at::Tensor::type() const’ is deprecated: 
Tensor.type() is deprecated. Instead use Tensor.options(), which in many cases (e.g. in a constructor) is a drop-in replaceme
nt. If you were using data from type(), that is now available from Tensor itself, so instead of tensor.type().scalar_type(), 
use tensor.scalar_type() instead and instead of tensor.type().backend() use tensor.device(). [-Wdeprecated-declarations]
     return tensors[0].type();
                            ^
In file included from ../aten/src/ATen/Tensor.h:3,
                 from ../aten/src/ATen/Context.h:4,
                 from ../aten/src/ATen/ATen.h:9,
                 from ../torch/csrc/utils/tensor_flatten.h:5,
                 from ../torch/csrc/utils/tensor_flatten.cpp:1:
aten/src/ATen/core/TensorBody.h:334:30: note: declared here
   DeprecatedTypeProperties & type() const {
                              ^~~~
../torch/csrc/utils/tensor_flatten.cpp: In function ‘std::vector<torch::utils::TensorGroup> torch::utils::take_tensors(at::Te
nsorList, size_t, bool)’:
../torch/csrc/utils/tensor_flatten.cpp:31:43: warning: ‘at::DeprecatedTypeProperties& at::Tensor::type() const’ is deprecated
: Tensor.type() is deprecated. Instead use Tensor.options(), which in many cases (e.g. in a constructor) is a drop-in replace
ment. If you were using data from type(), that is now available from Tensor itself, so instead of tensor.type().scalar_type()
, use tensor.scalar_type() instead and instead of tensor.type().backend() use tensor.device(). [-Wdeprecated-declarations]
     auto& type_group = groups[tensor.type().id()];
                                           ^
In file included from ../aten/src/ATen/Tensor.h:3,
                 from ../aten/src/ATen/Context.h:4,
                 from ../aten/src/ATen/ATen.h:9,
                 from ../torch/csrc/utils/tensor_flatten.h:5,
                 from ../torch/csrc/utils/tensor_flatten.cpp:1:
aten/src/ATen/core/TensorBody.h:334:30: note: declared here
   DeprecatedTypeProperties & type() const {
                              ^~~~
```

</details>


- [x] ivalue_test deprecated dict usage (#56303)

<details>

```
[3685/5420] Building CXX object caffe2/CMakeFiles/ivalue_test.dir/__/aten/src/ATen/test/ivalue_test.cpp.o
../aten/src/ATen/test/ivalue_test.cpp: In member function ‘virtual void c10::IValueTest_getSubValues_Test::TestBody()’:
../aten/src/ATen/test/ivalue_test.cpp:615:27: warning: ‘c10::IValue::IValue(std::unordered_map<Key, Value>) [with Key = long
int; Value = at::Tensor]’ is deprecated: IValues based on std::unordered_map<K, V> are slow and deprecated. Please use c10::D
ict<K, V> instead. [-Wdeprecated-declarations]
   IValue dict(std::move(m));
                           ^
In file included from ../aten/src/ATen/core/ivalue.h:1175,
                 from ../aten/src/ATen/record_function.h:3,
                 from ../aten/src/ATen/Dispatch.h:5,
                 from ../aten/src/ATen/ATen.h:13,
                 from ../aten/src/ATen/test/ivalue_test.cpp:1:
../aten/src/ATen/core/ivalue_inl.h:1217:8: note: declared here
 inline IValue::IValue(std::unordered_map<Key, Value> v)
        ^~~~~~
```

</details>


- [x] caffe2/utils/proto_utils.cc (#56186)

- [x] record_function_ops (#56543)

<details>

```
[4571/5420] Building CXX object caffe2/CMakeFiles/torch_cpu.dir/__/torch/csrc/autograd/record_function_ops.cpp.o
../torch/csrc/autograd/record_function_ops.cpp: In function ‘at::Tensor torch::autograd::profiler::record_function_enter(cons
t string&)’:
../torch/csrc/autograd/record_function_ops.cpp:22:78: warning: ‘at::Tensor at::cpp_custom_type_hack::create(std::unique_ptr<_
Tp>, c10::TensorOptions) [with T = at::RecordFunction]’ is deprecated: Use custom classes instead: https://pytorch.org/tutori
als/advanced/torch_script_custom_classes.html [-Wdeprecated-declarations]
   return at::cpp_custom_type_hack::create(std::move(rec), at::TensorOptions());
                                                                              ^
In file included from ../torch/csrc/autograd/record_function_ops.cpp:1:
../aten/src/ATen/cpp_custom_type_hack.h:83:8: note: declared here
 Tensor create(std::unique_ptr<T> ptr, TensorOptions options) {
        ^~~~~~
../torch/csrc/autograd/record_function_ops.cpp:22:78: warning: ‘at::Tensor at::cpp_custom_type_hack::create(std::unique_ptr<_
Tp>, c10::TensorOptions) [with T = at::RecordFunction]’ is deprecated: Use custom classes instead: https://pytorch.org/tutori
als/advanced/torch_script_custom_classes.html [-Wdeprecated-declarations]
   return at::cpp_custom_type_hack::create(std::move(rec), at::TensorOptions());
                                                                              ^
In file included from ../torch/csrc/autograd/record_function_ops.cpp:1:
../aten/src/ATen/cpp_custom_type_hack.h:83:8: note: declared here
 Tensor create(std::unique_ptr<T> ptr, TensorOptions options) {
        ^~~~~~
../torch/csrc/autograd/record_function_ops.cpp: In function ‘at::RecordFunction& torch::autograd::profiler::getRecordFunction
FromTensor(const at::Tensor&)’:
../torch/csrc/autograd/record_function_ops.cpp:26:72: warning: ‘T& at::cpp_custom_type_hack::cast(const at::Tensor&) [with T
= at::RecordFunction]’ is deprecated: Use custom classes instead: https://pytorch.org/tutorials/advanced/torch_script_custom_
classes.html [-Wdeprecated-declarations]
   auto& rec = at::cpp_custom_type_hack::cast<at::RecordFunction>(handle);
                                                                        ^
In file included from ../torch/csrc/autograd/record_function_ops.cpp:1:
../aten/src/ATen/cpp_custom_type_hack.h:69:4: note: declared here
 T& cast(const Tensor& packed) {
    ^~~~
../torch/csrc/autograd/record_function_ops.cpp:26:72: warning: ‘T& at::cpp_custom_type_hack::cast(const at::Tensor&) [with T
= at::RecordFunction]’ is deprecated: Use custom classes instead: https://pytorch.org/tutorials/advanced/torch_script_custom_
classes.html [-Wdeprecated-declarations]
   auto& rec = at::cpp_custom_type_hack::cast<at::RecordFunction>(handle);
                                                                        ^
In file included from ../torch/csrc/autograd/record_function_ops.cpp:1:
../aten/src/ATen/cpp_custom_type_hack.h:69:4: note: declared here
 T& cast(const Tensor& packed) {
    ^~~~
```

</details>


- [x] `tensor.is_variable()` in test/cpp/api/tensor.cpp (#56305)

<details>

```
[5176/5420] Building CXX object test_api/CMakeFiles/test_api.dir/tensor.cpp.o
In file included from ../cmake/../third_party/googletest/googletest/include/gtest/gtest.h:59,
                 from ../test/cpp/api/tensor.cpp:1:
../test/cpp/api/tensor.cpp: In function ‘void test_TorchTensorCtorSingleDimFloatingType_expected_dtype(c10::ScalarType)’:
../test/cpp/api/tensor.cpp:427:34: warning: ‘bool at::Tensor::is_variable() const’ is deprecated: Tensor.is_variable() is dep
recated; everything is a variable now. (If you want to assert that variable has been appropriately handled already, use at::i
mpl::variable_excluded_from_dispatch()) [-Wdeprecated-declarations]
   ASSERT_TRUE(tensor.is_variable());
                                  ^
In file included from ../aten/src/ATen/TensorIndexing.h:4,
                 from ../test/cpp/api/support.h:8,
                 from ../test/cpp/api/tensor.cpp:2:
aten/src/ATen/core/TensorBody.h:362:8: note: declared here
   bool is_variable() const noexcept {
        ^~~~~~~~~~~
In file included from ../cmake/../third_party/googletest/googletest/include/gtest/gtest.h:59,
                 from ../test/cpp/api/tensor.cpp:1:
../test/cpp/api/tensor.cpp:436:34: warning: ‘bool at::Tensor::is_variable() const’ is deprecated: Tensor.is_variable() is dep
recated; everything is a variable now. (If you want to assert that variable has been appropriately handled already, use at::i
mpl::variable_excluded_from_dispatch()) [-Wdeprecated-declarations]
   ASSERT_TRUE(tensor.is_variable());
                                  ^
In file included from ../aten/src/ATen/TensorIndexing.h:4,
                 from ../test/cpp/api/support.h:8,
                 from ../test/cpp/api/tensor.cpp:2:
aten/src/ATen/core/TensorBody.h:362:8: note: declared here
   bool is_variable() const noexcept {
        ^~~~~~~~~~~
In file included from ../cmake/../third_party/googletest/googletest/include/gtest/gtest.h:59,
                 from ../test/cpp/api/tensor.cpp:1:
../test/cpp/api/tensor.cpp:444:34: warning: ‘bool at::Tensor::is_variable() const’ is deprecated: Tensor.is_variable() is dep
recated; everything is a variable now. (If you want to assert that variable has been appropriately handled already, use at::i
mpl::variable_excluded_from_dispatch()) [-Wdeprecated-declarations]
   ASSERT_TRUE(tensor.is_variable());
                                  ^
In file included from ../aten/src/ATen/TensorIndexing.h:4,
                 from ../test/cpp/api/support.h:8,
                 from ../test/cpp/api/tensor.cpp:2:
aten/src/ATen/core/TensorBody.h:362:8: note: declared here
   bool is_variable() const noexcept {
        ^~~~~~~~~~~
```

</details>

@pytorch/pytorch-dev-infra