diff --git a/.clang-tidy b/.clang-tidy index 3b03412a4050..5776dabe0072 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -29,7 +29,6 @@ cppcoreguidelines-*, -cppcoreguidelines-pro-type-static-cast-downcast, -cppcoreguidelines-pro-type-union-access, -cppcoreguidelines-pro-type-vararg, --cppcoreguidelines-special-member-functions, -cppcoreguidelines-non-private-member-variables-in-classes, -facebook-hte-RelativeInclude, hicpp-exception-baseclass, @@ -64,5 +63,7 @@ readability-string-compare, HeaderFilterRegex: '^(aten/|c10/|torch/).*$' WarningsAsErrors: '*' CheckOptions: + cppcoreguidelines-special-member-functions.AllowSoleDefaultDtor: true + cppcoreguidelines-special-member-functions.AllowImplicitlyDeletedCopyOrMove: true misc-header-include-cycle.IgnoredFilesList: 'format.h;ivalue.h;custom_class.h;Dict.h;List.h;IListRef.h' ... diff --git a/aten/src/ATen/Context.h b/aten/src/ATen/Context.h index 40e843cbfa33..e37fa9ea516c 100644 --- a/aten/src/ATen/Context.h +++ b/aten/src/ATen/Context.h @@ -604,6 +604,10 @@ inline void manual_seed(uint64_t seed) { // NoTF32Guard disable_tf32; struct TORCH_API NoTF32Guard { NoTF32Guard(); + NoTF32Guard(NoTF32Guard&& other) = delete; + NoTF32Guard(const NoTF32Guard&) = delete; + NoTF32Guard& operator=(const NoTF32Guard&) = delete; + NoTF32Guard& operator=(NoTF32Guard&&) = delete; ~NoTF32Guard(); static bool should_disable_tf32(); @@ -613,6 +617,10 @@ struct TORCH_API NoTF32Guard { struct TORCH_API ROCmBackwardPassGuard { ROCmBackwardPassGuard(); + ROCmBackwardPassGuard(ROCmBackwardPassGuard&& other) = delete; + ROCmBackwardPassGuard(const ROCmBackwardPassGuard&) = delete; + ROCmBackwardPassGuard& operator=(const ROCmBackwardPassGuard&) = delete; + ROCmBackwardPassGuard& operator=(ROCmBackwardPassGuard&&) = delete; ~ROCmBackwardPassGuard(); static bool is_backward_pass(); }; diff --git a/aten/src/ATen/DynamicLibrary.h b/aten/src/ATen/DynamicLibrary.h index 523a21985f22..061456c081e6 100644 --- a/aten/src/ATen/DynamicLibrary.h +++ b/aten/src/ATen/DynamicLibrary.h @@ -16,6 +16,8 @@ namespace at { struct DynamicLibrary { AT_DISALLOW_COPY_AND_ASSIGN(DynamicLibrary); + DynamicLibrary(DynamicLibrary&& other) = delete; + DynamicLibrary& operator=(DynamicLibrary&&) = delete; TORCH_API DynamicLibrary( const char* name, diff --git a/aten/src/ATen/SparseCsrTensorUtils.h b/aten/src/ATen/SparseCsrTensorUtils.h index 2ec973013c49..3c6877083aee 100644 --- a/aten/src/ATen/SparseCsrTensorUtils.h +++ b/aten/src/ATen/SparseCsrTensorUtils.h @@ -155,6 +155,12 @@ class CheckSparseTensorInvariants { : old_state(at::globalContext().checkSparseTensorInvariants()) { at::globalContext().setCheckSparseTensorInvariants(state); } + CheckSparseTensorInvariants(CheckSparseTensorInvariants&& other) = delete; + CheckSparseTensorInvariants(const CheckSparseTensorInvariants&) = delete; + CheckSparseTensorInvariants& operator=(const CheckSparseTensorInvariants&) = + delete; + CheckSparseTensorInvariants& operator=(CheckSparseTensorInvariants&&) = + delete; ~CheckSparseTensorInvariants() { at::globalContext().setCheckSparseTensorInvariants(old_state); diff --git a/aten/src/ATen/TensorIterator.h b/aten/src/ATen/TensorIterator.h index 471faf664e27..7bbd68b91ba8 100644 --- a/aten/src/ATen/TensorIterator.h +++ b/aten/src/ATen/TensorIterator.h @@ -995,6 +995,7 @@ class TORCH_API TensorIteratorConfig final { /// TensorIterator that can use 32-bit indexing. Taken together the splits cover /// the original TensorIterator. struct TORCH_API SplitUntil32Bit { + // NOLINTNEXTLINE(cppcoreguidelines-special-member-functions) struct TORCH_API iterator { iterator() = default; iterator(const TensorIteratorBase& iter); diff --git a/aten/src/ATen/ThreadLocalState.h b/aten/src/ATen/ThreadLocalState.h index 2469cb1c3c47..bb28175c5f42 100644 --- a/aten/src/ATen/ThreadLocalState.h +++ b/aten/src/ATen/ThreadLocalState.h @@ -96,6 +96,10 @@ class TORCH_API ThreadLocalStateGuard { // set the given state across the thread boundary ThreadLocalState::setThreadLocalState(state); } + ThreadLocalStateGuard(ThreadLocalStateGuard&& other) = delete; + ThreadLocalStateGuard(const ThreadLocalStateGuard&) = delete; + ThreadLocalStateGuard& operator=(const ThreadLocalStateGuard&) = delete; + ThreadLocalStateGuard& operator=(ThreadLocalStateGuard&&) = delete; ~ThreadLocalStateGuard() { // restore previously set variables diff --git a/aten/src/ATen/core/Dict.h b/aten/src/ATen/core/Dict.h index a1d4da07520f..d187d7b7c116 100644 --- a/aten/src/ATen/core/Dict.h +++ b/aten/src/ATen/core/Dict.h @@ -206,6 +206,7 @@ template Dict toGenericDict(Dict +// NOLINTNEXTLINE(cppcoreguidelines-special-member-functions) class Dict final { private: static_assert((std::is_same_v && std::is_same_v) || guts::typelist::contains::value, "Invalid Key type for Dict. We only support int64_t, double, bool, and string."); diff --git a/aten/src/ATen/core/PythonFallbackKernel.h b/aten/src/ATen/core/PythonFallbackKernel.h index 67f24795eeb5..1d2b613166d3 100644 --- a/aten/src/ATen/core/PythonFallbackKernel.h +++ b/aten/src/ATen/core/PythonFallbackKernel.h @@ -6,6 +6,10 @@ namespace at::impl { struct TORCH_API RestorePythonTLSSnapshot { RestorePythonTLSSnapshot(); + RestorePythonTLSSnapshot(RestorePythonTLSSnapshot&& other) = delete; + RestorePythonTLSSnapshot(const RestorePythonTLSSnapshot&) = delete; + RestorePythonTLSSnapshot& operator=(const RestorePythonTLSSnapshot&) = delete; + RestorePythonTLSSnapshot& operator=(RestorePythonTLSSnapshot&&) = delete; ~RestorePythonTLSSnapshot(); private: @@ -18,6 +22,10 @@ private: struct TORCH_API MaybeSetTLSOnEntryGuard { public: MaybeSetTLSOnEntryGuard(); + MaybeSetTLSOnEntryGuard(MaybeSetTLSOnEntryGuard&& other) = delete; + MaybeSetTLSOnEntryGuard(const MaybeSetTLSOnEntryGuard&) = delete; + MaybeSetTLSOnEntryGuard& operator=(const MaybeSetTLSOnEntryGuard&) = delete; + MaybeSetTLSOnEntryGuard& operator=(MaybeSetTLSOnEntryGuard&&) = delete; ~MaybeSetTLSOnEntryGuard(); private: diff --git a/aten/src/ATen/core/QuantizerBase.h b/aten/src/ATen/core/QuantizerBase.h index 0d2eaeece889..a56ead7a30c6 100644 --- a/aten/src/ATen/core/QuantizerBase.h +++ b/aten/src/ATen/core/QuantizerBase.h @@ -40,7 +40,7 @@ struct TORCH_API Quantizer : public c10::intrusive_ptr_target { // NOLINTNEXTLINE(cppcoreguidelines-avoid-const-or-ref-data-members) const ScalarType scalar_type_; explicit Quantizer(ScalarType scalar_type) : scalar_type_(scalar_type) {} - ~Quantizer() override; + ~Quantizer() override = default; // Copied from torch/csrc/jit/ir/scope.h QuantizerPtr intrusive_from_this() { diff --git a/aten/src/ATen/core/Tensor.h b/aten/src/ATen/core/Tensor.h index de887a024c22..63b707767d34 100644 --- a/aten/src/ATen/core/Tensor.h +++ b/aten/src/ATen/core/Tensor.h @@ -4,6 +4,7 @@ #include namespace at { +// NOLINTNEXTLINE(cppcoreguidelines-special-member-functions) class TORCH_API OptionalTensorRef { public: OptionalTensorRef() = default; @@ -20,6 +21,7 @@ class TORCH_API OptionalTensorRef { OptionalTensorRef(const OptionalTensorRef& rhs) : ref_(Tensor::unsafe_borrow_t{}, rhs.ref_) {} + OptionalTensorRef(OptionalTensorRef&& rhs) = default; OptionalTensorRef& operator=(OptionalTensorRef rhs) { std::swap(ref_, rhs.ref_); return *this; @@ -59,6 +61,10 @@ class TORCH_API TensorRef { TensorRef(const TensorBase& src) : ref_(Tensor::unsafe_borrow_t{}, src) {} + TensorRef(TensorRef&& other) = default; + TensorRef(const TensorRef&) = default; + TensorRef& operator=(const TensorRef&) = default; + TensorRef& operator=(TensorRef&&) = default; const Tensor& operator*() const & { return ref_; diff --git a/aten/src/ATen/core/Vitals.h b/aten/src/ATen/core/Vitals.h index 8a7a51e81e1d..7ec213938d56 100644 --- a/aten/src/ATen/core/Vitals.h +++ b/aten/src/ATen/core/Vitals.h @@ -39,6 +39,8 @@ struct TORCH_API TorchVital { explicit TorchVital(std::string n) : name(std::move(n)) {} TorchVital(const TorchVital&) = default; TorchVital(TorchVital&&) = default; + TorchVital& operator=(const TorchVital&) = default; + TorchVital& operator=(TorchVital&&) = default; TorchVital() = delete; TorchVitalAttr& create(const std::string& attr); @@ -71,6 +73,7 @@ class TORCH_API APIVitals { APIVitals(APIVitals&& other) = delete; APIVitals& operator=(const APIVitals&) = delete; APIVitals& operator=(APIVitals&&) = delete; + ~APIVitals() = default; private: std::unordered_map name_map_; diff --git a/aten/src/ATen/core/dynamic_type.h b/aten/src/ATen/core/dynamic_type.h index 4ad833a295b1..697fcec39e34 100644 --- a/aten/src/ATen/core/dynamic_type.h +++ b/aten/src/ATen/core/dynamic_type.h @@ -159,6 +159,11 @@ class DynamicType : public SharedType { explicit DynamicType(Tag, Arguments); explicit DynamicType(Tag, std::string_view, Arguments); + DynamicType(DynamicType&& other) = delete; + DynamicType(const DynamicType&) = delete; + DynamicType& operator=(const DynamicType&) = delete; + DynamicType& operator=(DynamicType&&) = delete; + TypePtr containedType(size_t) const override; size_t containedTypeSize() const override; Tag tag() const { diff --git a/aten/src/ATen/core/jit_type.h b/aten/src/ATen/core/jit_type.h index 5951b4763be3..58d50de74fae 100644 --- a/aten/src/ATen/core/jit_type.h +++ b/aten/src/ATen/core/jit_type.h @@ -2204,7 +2204,7 @@ struct TORCH_API InterfaceType : public NamedType { return is_module_; } static const TypeKind Kind = TypeKind::InterfaceType; - ~InterfaceType() override; + ~InterfaceType() override = default; private: InterfaceType(QualifiedName name, bool is_module); static bool isSubTypeImpl( diff --git a/aten/src/ATen/core/jit_type_base.h b/aten/src/ATen/core/jit_type_base.h index 8904cd7bc431..de440787ee68 100644 --- a/aten/src/ATen/core/jit_type_base.h +++ b/aten/src/ATen/core/jit_type_base.h @@ -227,6 +227,7 @@ struct TORCH_API Type { SingletonOrSharedTypePtr(SingletonOrSharedTypePtr&&) noexcept = default; SingletonOrSharedTypePtr& operator=(const SingletonOrSharedTypePtr&) = default; SingletonOrSharedTypePtr& operator=(SingletonOrSharedTypePtr&&) noexcept = default; + ~SingletonOrSharedTypePtr() = default; T* get() const { return repr_.isSharedAndNonNull() ? repr_.shared_.repr_.get() : static_cast(repr_.rawRepr().first); diff --git a/aten/src/ATen/core/rref_interface.h b/aten/src/ATen/core/rref_interface.h index f0749d368792..70273f168d93 100644 --- a/aten/src/ATen/core/rref_interface.h +++ b/aten/src/ATen/core/rref_interface.h @@ -17,6 +17,7 @@ class C10_EXPORT RRefInterface : public c10::intrusive_ptr_target { // counting. RRefInterface(const RRefInterface& other) = delete; RRefInterface(RRefInterface&& other) = delete; + RRefInterface& operator=(const RRefInterface& other) = delete; RRefInterface& operator=(RRefInterface&& other) = delete; ~RRefInterface() override = default; diff --git a/aten/src/ATen/core/type.cpp b/aten/src/ATen/core/type.cpp index 92c30e6ec843..164ea6d44f58 100644 --- a/aten/src/ATen/core/type.cpp +++ b/aten/src/ATen/core/type.cpp @@ -1037,8 +1037,6 @@ InterfaceType::InterfaceType(QualifiedName name, bool is_module) methods_(std::make_shared>()), is_module_(is_module) {} -InterfaceType::~InterfaceType() = default; - bool containsAnyType(const TypePtr& type) { std::vector to_scan = { type }; while (!to_scan.empty()) { diff --git a/aten/src/ATen/functorch/DynamicLayer.cpp b/aten/src/ATen/functorch/DynamicLayer.cpp index 81b82f2556c1..9bdf155affc2 100644 --- a/aten/src/ATen/functorch/DynamicLayer.cpp +++ b/aten/src/ATen/functorch/DynamicLayer.cpp @@ -202,6 +202,8 @@ struct SaveLocalDispatchKeySet { } SaveLocalDispatchKeySet(const SaveLocalDispatchKeySet&) = delete; SaveLocalDispatchKeySet& operator=(const SaveLocalDispatchKeySet&) = delete; + SaveLocalDispatchKeySet(SaveLocalDispatchKeySet&&) = delete; + SaveLocalDispatchKeySet& operator=(SaveLocalDispatchKeySet&&) = delete; }; const std::vector& getDynamicLayerStack() { @@ -406,6 +408,10 @@ static void dump_local_tls() { struct WithoutTop { WithoutTop(); + WithoutTop(WithoutTop&& other) = delete; + WithoutTop(const WithoutTop&) = delete; + WithoutTop& operator=(const WithoutTop&) = delete; + WithoutTop& operator=(WithoutTop&&) = delete; ~WithoutTop(); DynamicLayer layer_; }; diff --git a/aten/src/ATen/quantized/Quantizer.cpp b/aten/src/ATen/quantized/Quantizer.cpp index ef8f8deb4973..fa48b33ce7c0 100644 --- a/aten/src/ATen/quantized/Quantizer.cpp +++ b/aten/src/ATen/quantized/Quantizer.cpp @@ -313,8 +313,6 @@ Tensor& PerChannelAffineFloatQParamsQuantizer::dequantize_out( return rtensor; } -Quantizer::~Quantizer() = default; - C10_EXPORT void set_quantizer_(const Tensor& self, ConstQuantizerPtr quantizer) { get_qtensorimpl(self)->set_quantizer_(quantizer); } diff --git a/aten/src/ATen/record_function.h b/aten/src/ATen/record_function.h index 15130c913675..52115b4a65af 100644 --- a/aten/src/ATen/record_function.h +++ b/aten/src/ATen/record_function.h @@ -353,6 +353,8 @@ struct TORCH_API RecordFunction { RecordFunction(const RecordFunction&) = delete; RecordFunction& operator=(const RecordFunction&) = delete; + RecordFunction(RecordFunction&&) = delete; + RecordFunction& operator=(RecordFunction&&) = delete; const char* name() const; @@ -764,6 +766,10 @@ class TORCH_API RecordFunctionGuard { enableRecordFunction(is_enabled); } + RecordFunctionGuard(RecordFunctionGuard&& other) = delete; + RecordFunctionGuard(const RecordFunctionGuard&) = delete; + RecordFunctionGuard& operator=(const RecordFunctionGuard&) = delete; + RecordFunctionGuard& operator=(RecordFunctionGuard&&) = delete; virtual ~RecordFunctionGuard() { enableRecordFunction(prev_value_); } diff --git a/c10/core/impl/PythonDispatcherTLS.h b/c10/core/impl/PythonDispatcherTLS.h index 12c0677f36fd..7b91aab686ec 100644 --- a/c10/core/impl/PythonDispatcherTLS.h +++ b/c10/core/impl/PythonDispatcherTLS.h @@ -16,6 +16,10 @@ struct C10_API DisablePythonDispatcher { PythonDispatcherTLS::set_state({}); } + DisablePythonDispatcher(DisablePythonDispatcher&& other) = delete; + DisablePythonDispatcher(const DisablePythonDispatcher&) = delete; + DisablePythonDispatcher& operator=(const DisablePythonDispatcher&) = delete; + DisablePythonDispatcher& operator=(DisablePythonDispatcher&&) = delete; ~DisablePythonDispatcher() { PythonDispatcherTLS::set_state(old_); } diff --git a/c10/test/util/Metaprogramming_test.cpp b/c10/test/util/Metaprogramming_test.cpp index ad301462bd51..a7bca7a5b511 100644 --- a/c10/test/util/Metaprogramming_test.cpp +++ b/c10/test/util/Metaprogramming_test.cpp @@ -5,7 +5,7 @@ using namespace c10::guts; -// NOLINTBEGIN(modernize*) +// NOLINTBEGIN(modernize*, cppcoreguidelines-special-member-functions) namespace { namespace test_function_traits { @@ -302,4 +302,4 @@ TEST(MetaprogrammingTest, TupleMap_canBeUsedWithAutoLambdas) { } // namespace test_tuple_map } // namespace -// NOLINTEND(modernize*) +// NOLINTEND(modernize*, cppcoreguidelines-special-member-functions) diff --git a/c10/test/util/ThreadLocal_test.cpp b/c10/test/util/ThreadLocal_test.cpp index bbc10c0c52e4..29e748e14890 100644 --- a/c10/test/util/ThreadLocal_test.cpp +++ b/c10/test/util/ThreadLocal_test.cpp @@ -148,6 +148,7 @@ TEST(ThreadLocalTest, TestThreadWithGlobalScopeVar) { TEST(ThreadLocalTest, TestObjectsAreReleased) { static std::atomic ctors{0}; static std::atomic dtors{0}; + // NOLINTNEXTLINE(cppcoreguidelines-special-member-functions) struct A { A() { ++ctors; @@ -183,6 +184,7 @@ TEST(ThreadLocalTest, TestObjectsAreReleased) { TEST(ThreadLocalTest, TestObjectsAreReleasedByNonstaticThreadLocal) { static std::atomic ctors(0); static std::atomic dtors(0); + // NOLINTNEXTLINE(cppcoreguidelines-special-member-functions) struct A { A() { ++ctors; diff --git a/c10/test/util/intrusive_ptr_test.cpp b/c10/test/util/intrusive_ptr_test.cpp index 14c12f422f2c..47e7942950ef 100644 --- a/c10/test/util/intrusive_ptr_test.cpp +++ b/c10/test/util/intrusive_ptr_test.cpp @@ -45,6 +45,7 @@ struct SomeChildClass : SomeBaseClass { SomeChildClass(int v) : SomeBaseClass(v) {} }; +// NOLINTNEXTLINE(cppcoreguidelines-special-member-functions) class DestructableMock : public intrusive_ptr_target { public: DestructableMock(bool* resourcesReleased, bool* wasDestructed) diff --git a/c10/test/util/logging_test.cpp b/c10/test/util/logging_test.cpp index 5798b37c18e3..c06dfb43d46c 100644 --- a/c10/test/util/logging_test.cpp +++ b/c10/test/util/logging_test.cpp @@ -81,6 +81,7 @@ TEST( } namespace { +// NOLINTNEXTLINE(cppcoreguidelines-special-member-functions) struct Noncopyable { int x; diff --git a/c10/test/util/typeid_test.cpp b/c10/test/util/typeid_test.cpp index 7587d5eefdbd..8e78ec84e530 100644 --- a/c10/test/util/typeid_test.cpp +++ b/c10/test/util/typeid_test.cpp @@ -70,6 +70,7 @@ TEST(TypeMetaTest, TypeMeta) { EXPECT_NE(bar_meta.name().find("TypeMetaTestBar"), c10::string_view::npos); } +// NOLINTNEXTLINE(cppcoreguidelines-special-member-functions) class ClassAllowAssignment { public: ClassAllowAssignment() = default; @@ -78,6 +79,7 @@ class ClassAllowAssignment { int x{42}; }; +// NOLINTNEXTLINE(cppcoreguidelines-special-member-functions) class ClassNoAssignment { public: ClassNoAssignment() = default; diff --git a/c10/util/DynamicCounter.cpp b/c10/util/DynamicCounter.cpp index 0b7906af1b12..cd9decfc41f3 100644 --- a/c10/util/DynamicCounter.cpp +++ b/c10/util/DynamicCounter.cpp @@ -52,6 +52,11 @@ struct DynamicCounter::Guard { } } + Guard(Guard&& other) = delete; + Guard(const Guard&) = delete; + Guard& operator=(const Guard&) = delete; + Guard& operator=(Guard&&) = delete; + ~Guard() { for (const auto& backend : backends_) { backend->unregisterCounter(key_); diff --git a/c10/util/Exception.h b/c10/util/Exception.h index 275526cf4008..e83b65cc5efc 100644 --- a/c10/util/Exception.h +++ b/c10/util/Exception.h @@ -205,6 +205,10 @@ class C10_API WarningHandlerGuard { : prev_handler_(c10::WarningUtils::get_warning_handler()) { c10::WarningUtils::set_warning_handler(new_handler); } + WarningHandlerGuard(WarningHandlerGuard&& other) = delete; + WarningHandlerGuard(const WarningHandlerGuard&) = delete; + WarningHandlerGuard& operator=(const WarningHandlerGuard&) = delete; + WarningHandlerGuard& operator=(WarningHandlerGuard&&) = delete; ~WarningHandlerGuard() { c10::WarningUtils::set_warning_handler(prev_handler_); } diff --git a/c10/util/LeftRight.h b/c10/util/LeftRight.h index 58145b2c779c..0ad9a1b34610 100644 --- a/c10/util/LeftRight.h +++ b/c10/util/LeftRight.h @@ -18,6 +18,8 @@ struct IncrementRAII final { ~IncrementRAII() { _counter->fetch_sub(1); } + IncrementRAII(IncrementRAII&&) = delete; + IncrementRAII& operator=(IncrementRAII&&) = delete; private: std::atomic* _counter; @@ -201,6 +203,7 @@ class RWSafeLeftRightWrapper final { RWSafeLeftRightWrapper(RWSafeLeftRightWrapper&&) noexcept = delete; RWSafeLeftRightWrapper& operator=(const RWSafeLeftRightWrapper&) = delete; RWSafeLeftRightWrapper& operator=(RWSafeLeftRightWrapper&&) noexcept = delete; + ~RWSafeLeftRightWrapper() = default; template // NOLINTNEXTLINE(cppcoreguidelines-missing-std-forward) diff --git a/c10/util/order_preserving_flat_hash_map.h b/c10/util/order_preserving_flat_hash_map.h index 021995600344..fd8196432c99 100644 --- a/c10/util/order_preserving_flat_hash_map.h +++ b/c10/util/order_preserving_flat_hash_map.h @@ -139,6 +139,7 @@ struct KeyOrValueEquality : functor_storage { }; static constexpr int8_t min_lookups = 4; template +// NOLINTNEXTLINE(cppcoreguidelines-special-member-functions) struct sherwood_v3_entry { // NOLINTNEXTLINE(modernize-use-equals-default) sherwood_v3_entry() {} diff --git a/torch/csrc/distributed/rpc/types.h b/torch/csrc/distributed/rpc/types.h index 7844ce270cd4..82cf528bb9bd 100644 --- a/torch/csrc/distributed/rpc/types.h +++ b/torch/csrc/distributed/rpc/types.h @@ -13,6 +13,10 @@ TORCH_API void disableJitRRefPickle(); struct TORCH_API JitRRefPickleGuard { JitRRefPickleGuard(); + JitRRefPickleGuard(JitRRefPickleGuard&& other) = delete; + JitRRefPickleGuard(const JitRRefPickleGuard&) = delete; + JitRRefPickleGuard& operator=(const JitRRefPickleGuard&) = delete; + JitRRefPickleGuard& operator=(JitRRefPickleGuard&&) = delete; ~JitRRefPickleGuard(); }; diff --git a/torch/csrc/dynamo/python_compiled_autograd.cpp b/torch/csrc/dynamo/python_compiled_autograd.cpp index 33dac77d7434..8bd192cde7b1 100644 --- a/torch/csrc/dynamo/python_compiled_autograd.cpp +++ b/torch/csrc/dynamo/python_compiled_autograd.cpp @@ -543,6 +543,10 @@ static PyObject* call_end_capture(PyObject* self, const variable_list& inputs) { struct ClosingTHPObjectPtr : public THPObjectPtr { ClosingTHPObjectPtr(PyObject* o) : THPObjectPtr(o) {} + ClosingTHPObjectPtr(ClosingTHPObjectPtr&& other) = default; + ClosingTHPObjectPtr(const ClosingTHPObjectPtr&) = delete; + ClosingTHPObjectPtr& operator=(const ClosingTHPObjectPtr&) = delete; + ClosingTHPObjectPtr& operator=(ClosingTHPObjectPtr&&) = default; ~ClosingTHPObjectPtr() { if (PyErr_Occurred()) { // do nothing, do not attempt to close diff --git a/torch/csrc/inductor/aoti_runner/model_container_runner_cuda.h b/torch/csrc/inductor/aoti_runner/model_container_runner_cuda.h index 5db82bf41366..2018cf7573e7 100644 --- a/torch/csrc/inductor/aoti_runner/model_container_runner_cuda.h +++ b/torch/csrc/inductor/aoti_runner/model_container_runner_cuda.h @@ -8,6 +8,7 @@ namespace torch::inductor { // NOTICE: Following APIs are subject to change due to active development // We provide NO BC guarantee for these APIs +// NOLINTNEXTLINE(cppcoreguidelines-special-member-functions) class TORCH_API AOTIModelContainerRunnerCuda : public AOTIModelContainerRunner { public: // @param device_str: cuda device string, e.g. "cuda", "cuda:0" diff --git a/torch/csrc/lazy/core/ir.cpp b/torch/csrc/lazy/core/ir.cpp index fe9cfba2556c..033e4f5cf00b 100644 --- a/torch/csrc/lazy/core/ir.cpp +++ b/torch/csrc/lazy/core/ir.cpp @@ -98,8 +98,6 @@ Node::Node(OpKind op, Shape shape, size_t num_outputs) : Node(op, num_outputs) { shapes_.push_back(std::move(shape)); } -Node::~Node() = default; - // Retrieves the full shape of the IR Node. c10::ArrayRef Node::shapes() const { return shapes_; diff --git a/torch/csrc/lazy/core/ir.h b/torch/csrc/lazy/core/ir.h index dd244b7442b2..8e384e7982bd 100644 --- a/torch/csrc/lazy/core/ir.h +++ b/torch/csrc/lazy/core/ir.h @@ -101,7 +101,7 @@ class TORCH_API Node { // Construct node with shape and no operands Node(OpKind op, Shape shape, size_t num_outputs = 1); - virtual ~Node(); + virtual ~Node() = default; const OpKind& op() const { return op_; diff --git a/torch/csrc/lazy/core/ir_metadata.h b/torch/csrc/lazy/core/ir_metadata.h index aeaacb596e0a..7e73a5931819 100644 --- a/torch/csrc/lazy/core/ir_metadata.h +++ b/torch/csrc/lazy/core/ir_metadata.h @@ -38,6 +38,10 @@ struct TORCH_API MetaData { struct TORCH_API ScopePusher { explicit ScopePusher(const std::string& name); ~ScopePusher(); + ScopePusher(ScopePusher&& other) = delete; + ScopePusher(const ScopePusher&) = delete; + ScopePusher& operator=(const ScopePusher&) = delete; + ScopePusher& operator=(ScopePusher&&) = delete; static void ResetScopes(); }; diff --git a/torch/csrc/lazy/core/metrics.h b/torch/csrc/lazy/core/metrics.h index 191baa5eb176..05b525778d9a 100644 --- a/torch/csrc/lazy/core/metrics.h +++ b/torch/csrc/lazy/core/metrics.h @@ -258,6 +258,10 @@ class TORCH_API TimedSection { public: explicit TimedSection(Metric* metric) : metric_(metric), start_(NowNs()) {} + TimedSection(TimedSection&& other) = delete; + TimedSection(const TimedSection&) = delete; + TimedSection& operator=(const TimedSection&) = delete; + TimedSection& operator=(TimedSection&&) = delete; ~TimedSection() { int64_t now = NowNs(); metric_->AddSample(now, static_cast(now - start_)); diff --git a/torch/csrc/lazy/core/tensor.h b/torch/csrc/lazy/core/tensor.h index dfa317d3b81f..b739399b6bbd 100644 --- a/torch/csrc/lazy/core/tensor.h +++ b/torch/csrc/lazy/core/tensor.h @@ -42,12 +42,18 @@ class TORCH_API LazyTensor : public c10::intrusive_ptr_target { Data(BackendDevice device) : device(std::move(device)), unique_id(GetNextTensorId()) {} + Data(Data&& other) = delete; + Data(const Data&) = delete; + Data& operator=(const Data&) = delete; + Data& operator=(Data&&) = delete; virtual ~Data(); BackendDataPtr handle; Value ir_value; std::optional tensor_data; + // NOLINTNEXTLINE(cppcoreguidelines-avoid-const-or-ref-data-members) const BackendDevice device; + // NOLINTNEXTLINE(cppcoreguidelines-avoid-const-or-ref-data-members) const int64_t unique_id = 0; size_t generation = 1; }; @@ -68,6 +74,8 @@ class TORCH_API LazyTensor : public c10::intrusive_ptr_target { LazyTensor() = delete; LazyTensor(const LazyTensor&) = default; LazyTensor(LazyTensor&&) noexcept = default; + LazyTensor& operator=(const LazyTensor&) = default; + LazyTensor& operator=(LazyTensor&&) noexcept = default; ~LazyTensor() override = default; diff --git a/torch/csrc/lazy/core/thread_pool.cpp b/torch/csrc/lazy/core/thread_pool.cpp index 3f87aaa96b51..e61827e5b0fd 100644 --- a/torch/csrc/lazy/core/thread_pool.cpp +++ b/torch/csrc/lazy/core/thread_pool.cpp @@ -26,6 +26,10 @@ class ThreadPool { }); } } + ThreadPool(const ThreadPool&) = delete; + ThreadPool(ThreadPool&&) = delete; + ThreadPool& operator=(const ThreadPool&) = delete; + ThreadPool& operator=(ThreadPool&&) = delete; ~ThreadPool() { { diff --git a/torch/csrc/lazy/core/thread_pool.h b/torch/csrc/lazy/core/thread_pool.h index 8caa1e0bbc45..2e0ae8f89d8e 100644 --- a/torch/csrc/lazy/core/thread_pool.h +++ b/torch/csrc/lazy/core/thread_pool.h @@ -13,6 +13,7 @@ namespace torch::lazy { +// NOLINTNEXTLINE(cppcoreguidelines-special-member-functions) class TORCH_API Completion { public: class Data; diff --git a/torch/csrc/monitor/counters.h b/torch/csrc/monitor/counters.h index bfb1a463b713..986dfb7b85ca 100644 --- a/torch/csrc/monitor/counters.h +++ b/torch/csrc/monitor/counters.h @@ -122,6 +122,10 @@ class Stat { maxSamples_(maxSamples) { detail::registerStat(this); } + Stat(const Stat&) = delete; + Stat(Stat&&) = delete; + Stat& operator=(const Stat&) = delete; + Stat& operator=(Stat&&) = delete; virtual ~Stat() { { diff --git a/torch/csrc/profiler/collection.cpp b/torch/csrc/profiler/collection.cpp index eefe5621a293..c5b0d9539d4f 100644 --- a/torch/csrc/profiler/collection.cpp +++ b/torch/csrc/profiler/collection.cpp @@ -402,6 +402,10 @@ struct StealOrDefault { explicit StealOrDefault(T& container) : container_{container}, it_{container.begin()} {} + StealOrDefault(const StealOrDefault&) = delete; + StealOrDefault(StealOrDefault&&) = delete; + StealOrDefault& operator=(const StealOrDefault&) = delete; + StealOrDefault& operator=(StealOrDefault&&) = delete; ~StealOrDefault() { container_.get().clear(); } diff --git a/torch/csrc/profiler/orchestration/observer.h b/torch/csrc/profiler/orchestration/observer.h index c3beb4cca4d0..272e2e4f9d5f 100644 --- a/torch/csrc/profiler/orchestration/observer.h +++ b/torch/csrc/profiler/orchestration/observer.h @@ -128,6 +128,10 @@ struct TORCH_API ProfilerConfig { // ---------------------------------------------------------------------------- struct TORCH_API ProfilerStateBase : public c10::MemoryReportingInfoBase { explicit ProfilerStateBase(ProfilerConfig config); + ProfilerStateBase(const ProfilerStateBase&) = delete; + ProfilerStateBase(ProfilerStateBase&&) = delete; + ProfilerStateBase& operator=(const ProfilerStateBase&) = delete; + ProfilerStateBase& operator=(ProfilerStateBase&&) = delete; ~ProfilerStateBase() override; static ProfilerStateBase* get(bool global);