Compile error PyTorch 2.0.1 / GCC 13.1.0

I came across a strange error when compiling PyTorch (only C++ API, Python disabled) on A64FX using GCC 13.1.0.

When compiling the file aten/src/ATen/native/mkldnn/Pooling.cpp GCC turns on -Werror without turning on -Wno-dangling-reference so that

aten/src/ATen/core/IListRef_inl.h:171:17: error: possibly dangling reference to a temporary [-Werror=dangling-reference]
  171 |     const auto& ivalue = (*it).get();

This seems to be triggered by line 534 in caffe2/CMakeLists.txt:

# Required workaround for LLVM 9 includes.
  set_source_files_properties(${TORCH_SRC_DIR}/csrc/jit/tensorexpr/llvm_jit.cpp PROPERTIES COMPILE_FLAGS -Wno-noexcept-type)
  # Force -Werror on several files
  set_source_files_properties(${CMAKE_CURRENT_LIST_DIR}/../aten/src/ATen/native/mkldnn/Pooling.cpp PROPERTIES COMPILE_FLAGS "-Werror")

Is this special treatment of the file really necessary? If so, one should maybe add -Wno-dangling-reference.

Could you create a Github issue for this warning/error so that the actual warning might get fixed, please?

Done #105728. Thank you!

1 Like