Skip to content

Commit

Permalink
Enable -Wunused-local-typedefs (pytorch#83708)
Browse files Browse the repository at this point in the history
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: pytorch#83708
Approved by: https://github.com/albanD
  • Loading branch information
peterbell10 authored and pytorchmergebot committed Aug 26, 2022
1 parent 65ea3d0 commit b429a17
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 5 deletions.
1 change: 0 additions & 1 deletion cmake/public/utils.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion test/cpp/api/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 0 additions & 2 deletions torch/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
10 changes: 9 additions & 1 deletion torch/csrc/api/include/torch/nn/pimpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<ImplType>`.
/// `Impl` is a type alias for `ImplType` which provides a way to call static
Expand All @@ -199,7 +207,7 @@ serialize::InputArchive& operator>>(
class Name : public torch::nn::ModuleHolder<ImplType> { /* NOLINT */ \
public: \
using torch::nn::ModuleHolder<ImplType>::ModuleHolder; \
using Impl = ImplType; \
using Impl TORCH_UNUSED_EXCEPT_CUDA = ImplType; \
}

/// Like `TORCH_MODULE_IMPL`, but defaults the `ImplType` name to `<Name>Impl`.
Expand Down

0 comments on commit b429a17

Please sign in to comment.