From b429a17545be8418f8d5887ad302c9b8af031177 Mon Sep 17 00:00:00 2001 From: Peter Bell Date: Thu, 25 Aug 2022 23:43:25 +0100 Subject: [PATCH] Enable -Wunused-local-typedefs (#83708) I recently had a PR reverted because it triggered an unused-local-typedefs warning, so disabling these in the CMake build is counter-productive. Pull Request resolved: https://github.com/pytorch/pytorch/pull/83708 Approved by: https://github.com/albanD --- cmake/public/utils.cmake | 1 - test/cpp/api/CMakeLists.txt | 1 - torch/CMakeLists.txt | 2 -- torch/csrc/api/include/torch/nn/pimpl.h | 10 +++++++++- 4 files changed, 9 insertions(+), 5 deletions(-) diff --git a/cmake/public/utils.cmake b/cmake/public/utils.cmake index e9152ab76449a5..b0c4cc6f08b56d 100644 --- a/cmake/public/utils.cmake +++ b/cmake/public/utils.cmake @@ -451,7 +451,6 @@ function(torch_compile_options libname) -Wno-unused-parameter -Wno-unused-function -Wno-unused-result - -Wno-unused-local-typedefs -Wno-missing-field-initializers -Wno-write-strings -Wno-unknown-pragmas diff --git a/test/cpp/api/CMakeLists.txt b/test/cpp/api/CMakeLists.txt index 1e205f56b4f14d..f1e1765af5de76 100644 --- a/test/cpp/api/CMakeLists.txt +++ b/test/cpp/api/CMakeLists.txt @@ -55,7 +55,6 @@ target_include_directories(test_api PRIVATE ${ATen_CPU_INCLUDE}) target_link_libraries(test_api PRIVATE torch gtest) if(NOT MSVC) target_compile_options_if_supported(test_api -Wno-unused-variable) - target_compile_options_if_supported(test_api -Wno-unused-local-typedefs) endif() if(USE_CUDA) diff --git a/torch/CMakeLists.txt b/torch/CMakeLists.txt index 1859d42365af71..7586745602fd01 100644 --- a/torch/CMakeLists.txt +++ b/torch/CMakeLists.txt @@ -286,7 +286,6 @@ if(USE_DEPLOY) add_library(torch_python_obj OBJECT ${TORCH_PYTHON_SRCS}) if(NOT MSVC) target_compile_options(torch_python_obj PRIVATE -Wno-unused-variable) - target_compile_options(torch_python_obj PRIVATE -Wno-unused-local-typedefs) endif() if(USE_DISTRIBUTED) # Set c10d-related compile definitions. For a "normal" build of @@ -401,7 +400,6 @@ endif() if(NOT MSVC) target_compile_options(torch_python PRIVATE -Wno-unused-variable) - target_compile_options(torch_python PRIVATE -Wno-unused-local-typedefs) endif() # Required workaround for generated sources diff --git a/torch/csrc/api/include/torch/nn/pimpl.h b/torch/csrc/api/include/torch/nn/pimpl.h index b3a2f2fd28c6d8..d66d83c257ebd0 100644 --- a/torch/csrc/api/include/torch/nn/pimpl.h +++ b/torch/csrc/api/include/torch/nn/pimpl.h @@ -191,6 +191,14 @@ serialize::InputArchive& operator>>( } // namespace nn } // namespace torch +// Workaround for CUDA 10.2 and below not allowing attribute unused on +// using declarations. +#ifdef __CUDACC__ +#define TORCH_UNUSED_EXCEPT_CUDA +#else +#define TORCH_UNUSED_EXCEPT_CUDA C10_UNUSED +#endif + /// Defines a class `Name` which inherits from `nn::ModuleHolder` to provide a /// wrapper over a `std::shared_ptr`. /// `Impl` is a type alias for `ImplType` which provides a way to call static @@ -199,7 +207,7 @@ serialize::InputArchive& operator>>( class Name : public torch::nn::ModuleHolder { /* NOLINT */ \ public: \ using torch::nn::ModuleHolder::ModuleHolder; \ - using Impl = ImplType; \ + using Impl TORCH_UNUSED_EXCEPT_CUDA = ImplType; \ } /// Like `TORCH_MODULE_IMPL`, but defaults the `ImplType` name to `Impl`.