Skip to content

Commit d558c1a

Browse files
cyyeverpytorchmergebot
authored andcommitted
Enable cppcoreguidelines-special-member-functions (pytorch#139132)
Fixes #ISSUE_NUMBER Pull Request resolved: pytorch#139132 Approved by: https://github.com/sraikund16
1 parent c0c6bf4 commit d558c1a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+130
-12
lines changed

.clang-tidy

+2-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ cppcoreguidelines-*,
2929
-cppcoreguidelines-pro-type-static-cast-downcast,
3030
-cppcoreguidelines-pro-type-union-access,
3131
-cppcoreguidelines-pro-type-vararg,
32-
-cppcoreguidelines-special-member-functions,
3332
-cppcoreguidelines-non-private-member-variables-in-classes,
3433
-facebook-hte-RelativeInclude,
3534
hicpp-exception-baseclass,
@@ -64,5 +63,7 @@ readability-string-compare,
6463
HeaderFilterRegex: '^(aten/|c10/|torch/).*$'
6564
WarningsAsErrors: '*'
6665
CheckOptions:
66+
cppcoreguidelines-special-member-functions.AllowSoleDefaultDtor: true
67+
cppcoreguidelines-special-member-functions.AllowImplicitlyDeletedCopyOrMove: true
6768
misc-header-include-cycle.IgnoredFilesList: 'format.h;ivalue.h;custom_class.h;Dict.h;List.h;IListRef.h'
6869
...

aten/src/ATen/Context.h

+8
Original file line numberDiff line numberDiff line change
@@ -604,6 +604,10 @@ inline void manual_seed(uint64_t seed) {
604604
// NoTF32Guard disable_tf32;
605605
struct TORCH_API NoTF32Guard {
606606
NoTF32Guard();
607+
NoTF32Guard(NoTF32Guard&& other) = delete;
608+
NoTF32Guard(const NoTF32Guard&) = delete;
609+
NoTF32Guard& operator=(const NoTF32Guard&) = delete;
610+
NoTF32Guard& operator=(NoTF32Guard&&) = delete;
607611
~NoTF32Guard();
608612
static bool should_disable_tf32();
609613

@@ -613,6 +617,10 @@ struct TORCH_API NoTF32Guard {
613617

614618
struct TORCH_API ROCmBackwardPassGuard {
615619
ROCmBackwardPassGuard();
620+
ROCmBackwardPassGuard(ROCmBackwardPassGuard&& other) = delete;
621+
ROCmBackwardPassGuard(const ROCmBackwardPassGuard&) = delete;
622+
ROCmBackwardPassGuard& operator=(const ROCmBackwardPassGuard&) = delete;
623+
ROCmBackwardPassGuard& operator=(ROCmBackwardPassGuard&&) = delete;
616624
~ROCmBackwardPassGuard();
617625
static bool is_backward_pass();
618626
};

aten/src/ATen/DynamicLibrary.h

+2
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ namespace at {
1616

1717
struct DynamicLibrary {
1818
AT_DISALLOW_COPY_AND_ASSIGN(DynamicLibrary);
19+
DynamicLibrary(DynamicLibrary&& other) = delete;
20+
DynamicLibrary& operator=(DynamicLibrary&&) = delete;
1921

2022
TORCH_API DynamicLibrary(
2123
const char* name,

aten/src/ATen/SparseCsrTensorUtils.h

+6
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,12 @@ class CheckSparseTensorInvariants {
155155
: old_state(at::globalContext().checkSparseTensorInvariants()) {
156156
at::globalContext().setCheckSparseTensorInvariants(state);
157157
}
158+
CheckSparseTensorInvariants(CheckSparseTensorInvariants&& other) = delete;
159+
CheckSparseTensorInvariants(const CheckSparseTensorInvariants&) = delete;
160+
CheckSparseTensorInvariants& operator=(const CheckSparseTensorInvariants&) =
161+
delete;
162+
CheckSparseTensorInvariants& operator=(CheckSparseTensorInvariants&&) =
163+
delete;
158164

159165
~CheckSparseTensorInvariants() {
160166
at::globalContext().setCheckSparseTensorInvariants(old_state);

aten/src/ATen/TensorIterator.h

+1
Original file line numberDiff line numberDiff line change
@@ -995,6 +995,7 @@ class TORCH_API TensorIteratorConfig final {
995995
/// TensorIterator that can use 32-bit indexing. Taken together the splits cover
996996
/// the original TensorIterator.
997997
struct TORCH_API SplitUntil32Bit {
998+
// NOLINTNEXTLINE(cppcoreguidelines-special-member-functions)
998999
struct TORCH_API iterator {
9991000
iterator() = default;
10001001
iterator(const TensorIteratorBase& iter);

aten/src/ATen/ThreadLocalState.h

+4
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,10 @@ class TORCH_API ThreadLocalStateGuard {
9696
// set the given state across the thread boundary
9797
ThreadLocalState::setThreadLocalState(state);
9898
}
99+
ThreadLocalStateGuard(ThreadLocalStateGuard&& other) = delete;
100+
ThreadLocalStateGuard(const ThreadLocalStateGuard&) = delete;
101+
ThreadLocalStateGuard& operator=(const ThreadLocalStateGuard&) = delete;
102+
ThreadLocalStateGuard& operator=(ThreadLocalStateGuard&&) = delete;
99103

100104
~ThreadLocalStateGuard() {
101105
// restore previously set variables

aten/src/ATen/core/Dict.h

+1
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,7 @@ template<class Key, class Value> Dict<IValue, IValue> toGenericDict(Dict<Key, Va
206206
* for the kernel API.
207207
*/
208208
template<class Key, class Value>
209+
// NOLINTNEXTLINE(cppcoreguidelines-special-member-functions)
209210
class Dict final {
210211
private:
211212
static_assert((std::is_same_v<IValue, Key> && std::is_same_v<IValue, Value>) || guts::typelist::contains<impl::valid_dict_key_types, Key>::value, "Invalid Key type for Dict. We only support int64_t, double, bool, and string.");

aten/src/ATen/core/PythonFallbackKernel.h

+8
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ namespace at::impl {
66

77
struct TORCH_API RestorePythonTLSSnapshot {
88
RestorePythonTLSSnapshot();
9+
RestorePythonTLSSnapshot(RestorePythonTLSSnapshot&& other) = delete;
10+
RestorePythonTLSSnapshot(const RestorePythonTLSSnapshot&) = delete;
11+
RestorePythonTLSSnapshot& operator=(const RestorePythonTLSSnapshot&) = delete;
12+
RestorePythonTLSSnapshot& operator=(RestorePythonTLSSnapshot&&) = delete;
913
~RestorePythonTLSSnapshot();
1014

1115
private:
@@ -18,6 +22,10 @@ struct TORCH_API RestorePythonTLSSnapshot {
1822
struct TORCH_API MaybeSetTLSOnEntryGuard {
1923
public:
2024
MaybeSetTLSOnEntryGuard();
25+
MaybeSetTLSOnEntryGuard(MaybeSetTLSOnEntryGuard&& other) = delete;
26+
MaybeSetTLSOnEntryGuard(const MaybeSetTLSOnEntryGuard&) = delete;
27+
MaybeSetTLSOnEntryGuard& operator=(const MaybeSetTLSOnEntryGuard&) = delete;
28+
MaybeSetTLSOnEntryGuard& operator=(MaybeSetTLSOnEntryGuard&&) = delete;
2129
~MaybeSetTLSOnEntryGuard();
2230

2331
private:

aten/src/ATen/core/QuantizerBase.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ struct TORCH_API Quantizer : public c10::intrusive_ptr_target {
4040
// NOLINTNEXTLINE(cppcoreguidelines-avoid-const-or-ref-data-members)
4141
const ScalarType scalar_type_;
4242
explicit Quantizer(ScalarType scalar_type) : scalar_type_(scalar_type) {}
43-
~Quantizer() override;
43+
~Quantizer() override = default;
4444

4545
// Copied from torch/csrc/jit/ir/scope.h
4646
QuantizerPtr intrusive_from_this() {

aten/src/ATen/core/Tensor.h

+6
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include <c10/util/Exception.h>
55

66
namespace at {
7+
// NOLINTNEXTLINE(cppcoreguidelines-special-member-functions)
78
class TORCH_API OptionalTensorRef {
89
public:
910
OptionalTensorRef() = default;
@@ -20,6 +21,7 @@ class TORCH_API OptionalTensorRef {
2021
OptionalTensorRef(const OptionalTensorRef& rhs)
2122
: ref_(Tensor::unsafe_borrow_t{}, rhs.ref_) {}
2223

24+
OptionalTensorRef(OptionalTensorRef&& rhs) = default;
2325
OptionalTensorRef& operator=(OptionalTensorRef rhs) {
2426
std::swap(ref_, rhs.ref_);
2527
return *this;
@@ -59,6 +61,10 @@ class TORCH_API TensorRef {
5961

6062
TensorRef(const TensorBase& src)
6163
: ref_(Tensor::unsafe_borrow_t{}, src) {}
64+
TensorRef(TensorRef&& other) = default;
65+
TensorRef(const TensorRef&) = default;
66+
TensorRef& operator=(const TensorRef&) = default;
67+
TensorRef& operator=(TensorRef&&) = default;
6268

6369
const Tensor& operator*() const & {
6470
return ref_;

aten/src/ATen/core/Vitals.h

+3
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ struct TORCH_API TorchVital {
3939
explicit TorchVital(std::string n) : name(std::move(n)) {}
4040
TorchVital(const TorchVital&) = default;
4141
TorchVital(TorchVital&&) = default;
42+
TorchVital& operator=(const TorchVital&) = default;
43+
TorchVital& operator=(TorchVital&&) = default;
4244
TorchVital() = delete;
4345

4446
TorchVitalAttr& create(const std::string& attr);
@@ -71,6 +73,7 @@ class TORCH_API APIVitals {
7173
APIVitals(APIVitals&& other) = delete;
7274
APIVitals& operator=(const APIVitals&) = delete;
7375
APIVitals& operator=(APIVitals&&) = delete;
76+
~APIVitals() = default;
7477

7578
private:
7679
std::unordered_map<std::string, TorchVital> name_map_;

aten/src/ATen/core/dynamic_type.h

+5
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,11 @@ class DynamicType : public SharedType {
159159
explicit DynamicType(Tag, Arguments);
160160
explicit DynamicType(Tag, std::string_view, Arguments);
161161

162+
DynamicType(DynamicType&& other) = delete;
163+
DynamicType(const DynamicType&) = delete;
164+
DynamicType& operator=(const DynamicType&) = delete;
165+
DynamicType& operator=(DynamicType&&) = delete;
166+
162167
TypePtr containedType(size_t) const override;
163168
size_t containedTypeSize() const override;
164169
Tag tag() const {

aten/src/ATen/core/jit_type.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -2204,7 +2204,7 @@ struct TORCH_API InterfaceType : public NamedType {
22042204
return is_module_;
22052205
}
22062206
static const TypeKind Kind = TypeKind::InterfaceType;
2207-
~InterfaceType() override;
2207+
~InterfaceType() override = default;
22082208
private:
22092209
InterfaceType(QualifiedName name, bool is_module);
22102210
static bool isSubTypeImpl(

aten/src/ATen/core/jit_type_base.h

+1
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,7 @@ struct TORCH_API Type {
227227
SingletonOrSharedTypePtr(SingletonOrSharedTypePtr&&) noexcept = default;
228228
SingletonOrSharedTypePtr& operator=(const SingletonOrSharedTypePtr&) = default;
229229
SingletonOrSharedTypePtr& operator=(SingletonOrSharedTypePtr&&) noexcept = default;
230+
~SingletonOrSharedTypePtr() = default;
230231

231232
T* get() const {
232233
return repr_.isSharedAndNonNull() ? repr_.shared_.repr_.get() : static_cast<T*>(repr_.rawRepr().first);

aten/src/ATen/core/rref_interface.h

+1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ class C10_EXPORT RRefInterface : public c10::intrusive_ptr_target {
1717
// counting.
1818
RRefInterface(const RRefInterface& other) = delete;
1919
RRefInterface(RRefInterface&& other) = delete;
20+
RRefInterface& operator=(const RRefInterface& other) = delete;
2021
RRefInterface& operator=(RRefInterface&& other) = delete;
2122

2223
~RRefInterface() override = default;

aten/src/ATen/core/type.cpp

-2
Original file line numberDiff line numberDiff line change
@@ -1037,8 +1037,6 @@ InterfaceType::InterfaceType(QualifiedName name, bool is_module)
10371037
methods_(std::make_shared<std::vector<FunctionSchema>>()),
10381038
is_module_(is_module) {}
10391039

1040-
InterfaceType::~InterfaceType() = default;
1041-
10421040
bool containsAnyType(const TypePtr& type) {
10431041
std::vector<TypePtr> to_scan = { type };
10441042
while (!to_scan.empty()) {

aten/src/ATen/functorch/DynamicLayer.cpp

+6
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,8 @@ struct SaveLocalDispatchKeySet {
202202
}
203203
SaveLocalDispatchKeySet(const SaveLocalDispatchKeySet&) = delete;
204204
SaveLocalDispatchKeySet& operator=(const SaveLocalDispatchKeySet&) = delete;
205+
SaveLocalDispatchKeySet(SaveLocalDispatchKeySet&&) = delete;
206+
SaveLocalDispatchKeySet& operator=(SaveLocalDispatchKeySet&&) = delete;
205207
};
206208

207209
const std::vector<DynamicLayer>& getDynamicLayerStack() {
@@ -406,6 +408,10 @@ static void dump_local_tls() {
406408

407409
struct WithoutTop {
408410
WithoutTop();
411+
WithoutTop(WithoutTop&& other) = delete;
412+
WithoutTop(const WithoutTop&) = delete;
413+
WithoutTop& operator=(const WithoutTop&) = delete;
414+
WithoutTop& operator=(WithoutTop&&) = delete;
409415
~WithoutTop();
410416
DynamicLayer layer_;
411417
};

aten/src/ATen/quantized/Quantizer.cpp

-2
Original file line numberDiff line numberDiff line change
@@ -313,8 +313,6 @@ Tensor& PerChannelAffineFloatQParamsQuantizer::dequantize_out(
313313
return rtensor;
314314
}
315315

316-
Quantizer::~Quantizer() = default;
317-
318316
C10_EXPORT void set_quantizer_(const Tensor& self, ConstQuantizerPtr quantizer) {
319317
get_qtensorimpl(self)->set_quantizer_(quantizer);
320318
}

aten/src/ATen/record_function.h

+6
Original file line numberDiff line numberDiff line change
@@ -353,6 +353,8 @@ struct TORCH_API RecordFunction {
353353

354354
RecordFunction(const RecordFunction&) = delete;
355355
RecordFunction& operator=(const RecordFunction&) = delete;
356+
RecordFunction(RecordFunction&&) = delete;
357+
RecordFunction& operator=(RecordFunction&&) = delete;
356358

357359
const char* name() const;
358360

@@ -764,6 +766,10 @@ class TORCH_API RecordFunctionGuard {
764766
enableRecordFunction(is_enabled);
765767
}
766768

769+
RecordFunctionGuard(RecordFunctionGuard&& other) = delete;
770+
RecordFunctionGuard(const RecordFunctionGuard&) = delete;
771+
RecordFunctionGuard& operator=(const RecordFunctionGuard&) = delete;
772+
RecordFunctionGuard& operator=(RecordFunctionGuard&&) = delete;
767773
virtual ~RecordFunctionGuard() {
768774
enableRecordFunction(prev_value_);
769775
}

c10/core/impl/PythonDispatcherTLS.h

+4
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ struct C10_API DisablePythonDispatcher {
1616
PythonDispatcherTLS::set_state({});
1717
}
1818

19+
DisablePythonDispatcher(DisablePythonDispatcher&& other) = delete;
20+
DisablePythonDispatcher(const DisablePythonDispatcher&) = delete;
21+
DisablePythonDispatcher& operator=(const DisablePythonDispatcher&) = delete;
22+
DisablePythonDispatcher& operator=(DisablePythonDispatcher&&) = delete;
1923
~DisablePythonDispatcher() {
2024
PythonDispatcherTLS::set_state(old_);
2125
}

c10/test/util/Metaprogramming_test.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
using namespace c10::guts;
77

8-
// NOLINTBEGIN(modernize*)
8+
// NOLINTBEGIN(modernize*, cppcoreguidelines-special-member-functions)
99
namespace {
1010

1111
namespace test_function_traits {
@@ -302,4 +302,4 @@ TEST(MetaprogrammingTest, TupleMap_canBeUsedWithAutoLambdas) {
302302
} // namespace test_tuple_map
303303

304304
} // namespace
305-
// NOLINTEND(modernize*)
305+
// NOLINTEND(modernize*, cppcoreguidelines-special-member-functions)

c10/test/util/ThreadLocal_test.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,7 @@ TEST(ThreadLocalTest, TestThreadWithGlobalScopeVar) {
148148
TEST(ThreadLocalTest, TestObjectsAreReleased) {
149149
static std::atomic<int> ctors{0};
150150
static std::atomic<int> dtors{0};
151+
// NOLINTNEXTLINE(cppcoreguidelines-special-member-functions)
151152
struct A {
152153
A() {
153154
++ctors;
@@ -183,6 +184,7 @@ TEST(ThreadLocalTest, TestObjectsAreReleased) {
183184
TEST(ThreadLocalTest, TestObjectsAreReleasedByNonstaticThreadLocal) {
184185
static std::atomic<int> ctors(0);
185186
static std::atomic<int> dtors(0);
187+
// NOLINTNEXTLINE(cppcoreguidelines-special-member-functions)
186188
struct A {
187189
A() {
188190
++ctors;

c10/test/util/intrusive_ptr_test.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ struct SomeChildClass : SomeBaseClass {
4545
SomeChildClass(int v) : SomeBaseClass(v) {}
4646
};
4747

48+
// NOLINTNEXTLINE(cppcoreguidelines-special-member-functions)
4849
class DestructableMock : public intrusive_ptr_target {
4950
public:
5051
DestructableMock(bool* resourcesReleased, bool* wasDestructed)

c10/test/util/logging_test.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ TEST(
8181
}
8282

8383
namespace {
84+
// NOLINTNEXTLINE(cppcoreguidelines-special-member-functions)
8485
struct Noncopyable {
8586
int x;
8687

c10/test/util/typeid_test.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ TEST(TypeMetaTest, TypeMeta) {
7070
EXPECT_NE(bar_meta.name().find("TypeMetaTestBar"), c10::string_view::npos);
7171
}
7272

73+
// NOLINTNEXTLINE(cppcoreguidelines-special-member-functions)
7374
class ClassAllowAssignment {
7475
public:
7576
ClassAllowAssignment() = default;
@@ -78,6 +79,7 @@ class ClassAllowAssignment {
7879
int x{42};
7980
};
8081

82+
// NOLINTNEXTLINE(cppcoreguidelines-special-member-functions)
8183
class ClassNoAssignment {
8284
public:
8385
ClassNoAssignment() = default;

c10/util/DynamicCounter.cpp

+5
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,11 @@ struct DynamicCounter::Guard {
5252
}
5353
}
5454

55+
Guard(Guard&& other) = delete;
56+
Guard(const Guard&) = delete;
57+
Guard& operator=(const Guard&) = delete;
58+
Guard& operator=(Guard&&) = delete;
59+
5560
~Guard() {
5661
for (const auto& backend : backends_) {
5762
backend->unregisterCounter(key_);

c10/util/Exception.h

+4
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,10 @@ class C10_API WarningHandlerGuard {
205205
: prev_handler_(c10::WarningUtils::get_warning_handler()) {
206206
c10::WarningUtils::set_warning_handler(new_handler);
207207
}
208+
WarningHandlerGuard(WarningHandlerGuard&& other) = delete;
209+
WarningHandlerGuard(const WarningHandlerGuard&) = delete;
210+
WarningHandlerGuard& operator=(const WarningHandlerGuard&) = delete;
211+
WarningHandlerGuard& operator=(WarningHandlerGuard&&) = delete;
208212
~WarningHandlerGuard() {
209213
c10::WarningUtils::set_warning_handler(prev_handler_);
210214
}

c10/util/LeftRight.h

+3
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ struct IncrementRAII final {
1818
~IncrementRAII() {
1919
_counter->fetch_sub(1);
2020
}
21+
IncrementRAII(IncrementRAII&&) = delete;
22+
IncrementRAII& operator=(IncrementRAII&&) = delete;
2123

2224
private:
2325
std::atomic<int32_t>* _counter;
@@ -201,6 +203,7 @@ class RWSafeLeftRightWrapper final {
201203
RWSafeLeftRightWrapper(RWSafeLeftRightWrapper&&) noexcept = delete;
202204
RWSafeLeftRightWrapper& operator=(const RWSafeLeftRightWrapper&) = delete;
203205
RWSafeLeftRightWrapper& operator=(RWSafeLeftRightWrapper&&) noexcept = delete;
206+
~RWSafeLeftRightWrapper() = default;
204207

205208
template <typename F>
206209
// NOLINTNEXTLINE(cppcoreguidelines-missing-std-forward)

c10/util/order_preserving_flat_hash_map.h

+1
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ struct KeyOrValueEquality : functor_storage<bool, key_equal> {
139139
};
140140
static constexpr int8_t min_lookups = 4;
141141
template <typename T>
142+
// NOLINTNEXTLINE(cppcoreguidelines-special-member-functions)
142143
struct sherwood_v3_entry {
143144
// NOLINTNEXTLINE(modernize-use-equals-default)
144145
sherwood_v3_entry() {}

torch/csrc/distributed/rpc/types.h

+4
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ TORCH_API void disableJitRRefPickle();
1313

1414
struct TORCH_API JitRRefPickleGuard {
1515
JitRRefPickleGuard();
16+
JitRRefPickleGuard(JitRRefPickleGuard&& other) = delete;
17+
JitRRefPickleGuard(const JitRRefPickleGuard&) = delete;
18+
JitRRefPickleGuard& operator=(const JitRRefPickleGuard&) = delete;
19+
JitRRefPickleGuard& operator=(JitRRefPickleGuard&&) = delete;
1620
~JitRRefPickleGuard();
1721
};
1822

0 commit comments

Comments
 (0)