Skip to content

Commit 4d9b5a8

Browse files
cyyeverpytorchmergebot
authored andcommitted
[3/N] Fix cppcoreguidelines-special-member-functions warnings (pytorch#138796)
Fixes #ISSUE_NUMBER Pull Request resolved: pytorch#138796 Approved by: https://github.com/ezyang
1 parent 2265c2d commit 4d9b5a8

18 files changed

+55
-8
lines changed

aten/src/ATen/TensorIterator.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1483,8 +1483,6 @@ FastSetupType TensorIteratorBase::compute_fast_setup_type(const TensorIteratorCo
14831483
return FastSetupType::NONE;
14841484
}
14851485

1486-
TensorIteratorBase::TensorIteratorBase() = default;
1487-
14881486
void TensorIteratorBase::build(TensorIteratorConfig& config) {
14891487
// populate some persistent configuration fields
14901488
is_reduction_ = config.is_reduction_;

aten/src/ATen/TensorIterator.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,6 @@ struct TORCH_API TensorIteratorBase : public impl::MetaBase {
250250
using PtrVector = SmallVector<char*, 4>;
251251
using StrideVector = SmallVector<int64_t, 6>;
252252

253-
TensorIteratorBase();
254253
void build(TensorIteratorConfig&);
255254

256255
// The inner-loop function operates on the fastest moving dimension. It
@@ -788,6 +787,9 @@ class TORCH_API TensorIteratorConfig final {
788787
TensorIteratorConfig() = default;
789788

790789
C10_DISABLE_COPY_AND_ASSIGN(TensorIteratorConfig);
790+
TensorIteratorConfig(TensorIteratorConfig&&) = default;
791+
TensorIteratorConfig& operator=(TensorIteratorConfig&&) = default;
792+
~TensorIteratorConfig() = default;
791793

792794
/// Construction
793795
// Stores input/output Tensors without incrementing the reference count.
@@ -997,6 +999,8 @@ struct TORCH_API SplitUntil32Bit {
997999
iterator() = default;
9981000
iterator(const TensorIteratorBase& iter);
9991001
iterator(iterator&&) = default;
1002+
iterator& operator=(iterator&&) = default;
1003+
~iterator() = default;
10001004

10011005
// Guaranteed to be a TensorIterator proper!
10021006
TensorIterator& operator*() const;

aten/src/ATen/code_template.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,10 @@ namespace at::jit {
1919
struct TemplateEnv {
2020
TemplateEnv() = default;
2121
TemplateEnv(TemplateEnv& parent) : parent(&parent) {}
22+
TemplateEnv(TemplateEnv&&) = delete;
2223
TemplateEnv& operator=(const TemplateEnv& parent) = delete;
24+
TemplateEnv& operator=(TemplateEnv&& parent) = delete;
25+
~TemplateEnv() = default;
2326

2427
using string_list = std::vector<std::string>;
2528

aten/src/ATen/core/Array.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,16 @@ struct Array {
2323
C10_HOST_DEVICE Array() = default;
2424
C10_HOST_DEVICE Array(const Array&) = default;
2525
C10_HOST_DEVICE Array& operator=(const Array&) = default;
26+
C10_HOST_DEVICE Array(Array&&) = default;
27+
C10_HOST_DEVICE Array& operator=(Array&&) = default;
28+
C10_HOST_DEVICE ~Array() = default;
2629
#else
2730
Array() = default;
2831
Array(const Array&) = default;
2932
Array& operator=(const Array&) = default;
33+
Array(Array&&) = default;
34+
Array& operator=(Array&&) = default;
35+
~Array() = default;
3036
#endif
3137
static constexpr int size() {
3238
return size_;

aten/src/ATen/core/Dict.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ class DictEntryRef final {
8383
static_assert(std::is_constructible_v<Value, Value_>, "Wrong type for the value argument of setValue()");
8484
iterator_->second = Value(std::forward<Value_>(value));
8585
}
86+
~DictEntryRef() = default;
8687

8788
private:
8889
// allow copying and moving, but only our friends (i.e. the Dict class) can do

aten/src/ATen/core/Formatting.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,16 +50,20 @@ inline std::ios_base& defaultfloat(std::ios_base& __base) {
5050
//saves/restores number formatting inside scope
5151
struct FormatGuard {
5252
FormatGuard(std::ostream & out)
53-
: out(out), saved(nullptr) {
53+
: out(out) {
5454
saved.copyfmt(out);
5555
}
5656
~FormatGuard() {
5757
out.copyfmt(saved);
5858
}
59+
FormatGuard(const FormatGuard&) = delete;
60+
FormatGuard(FormatGuard&&) = delete;
61+
FormatGuard& operator=(const FormatGuard&) = delete;
62+
FormatGuard& operator=(FormatGuard&&) = delete;
5963
private:
6064
// NOLINTNEXTLINE(cppcoreguidelines-avoid-const-or-ref-data-members)
6165
std::ostream & out;
62-
std::ios saved;
66+
std::ios saved{nullptr};
6367
};
6468

6569
std::ostream& operator<<(std::ostream & out, const DeprecatedTypeProperties& t) {

aten/src/ATen/core/List.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ class ListElementReference final {
8888

8989
ListElementReference(const ListElementReference&) = delete;
9090
ListElementReference& operator=(const ListElementReference&) = delete;
91+
~ListElementReference() = default;
9192

9293
private:
9394
ListElementReference(Iterator iter)
@@ -234,6 +235,7 @@ const IValue* ptr_to_first_element(const List<IValue>& list);
234235
* breaking backwards compatibility for the kernel API.
235236
*/
236237
template<class T>
238+
// NOLINTNEXTLINE(cppcoreguidelines-special-member-functions)
237239
class List final {
238240
private:
239241
// This is an intrusive_ptr because List is a pointer type.
@@ -273,6 +275,7 @@ class List final {
273275

274276
List(const List&) = default;
275277
List& operator=(const List&) = default;
278+
~List() = default;
276279

277280
/**
278281
* Create a new List pointing to a deep copy of the same data.

aten/src/ATen/core/List_test.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
using namespace c10;
55

6-
// NOLINTBEGIN(performance-move-const-arg, bugprone-use-after-move)
6+
// NOLINTBEGIN(performance-move-const-arg, bugprone-use-after-move, *analyzer*Move)
77
TEST(ListTestIValueBasedList, givenEmptyList_whenCallingEmpty_thenReturnsTrue) {
88
List<string> list;
99
EXPECT_TRUE(list.empty());
@@ -1162,4 +1162,4 @@ TEST(ListTest, toTypedList) {
11621162
genericList = impl::toList(std::move(stringList));
11631163
EXPECT_THROW(c10::impl::toTypedList<int64_t>(std::move(genericList)), c10::Error);
11641164
}
1165-
// NOLINTEND(performance-move-const-arg, bugprone-use-after-move)
1165+
// NOLINTEND(performance-move-const-arg, bugprone-use-after-move, *analyzer*Move)

aten/src/ATen/core/NamedTensor.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,10 @@ struct TORCH_API NoNamesGuard {
8282
NoNamesGuard() : prev_mode(NamesMode::is_enabled()) {
8383
NamesMode::set_enabled(false);
8484
}
85+
NoNamesGuard(const NoNamesGuard&) = delete;
86+
NoNamesGuard(NoNamesGuard&&) = delete;
87+
NoNamesGuard& operator=(const NoNamesGuard&) = delete;
88+
NoNamesGuard& operator=(NoNamesGuard&&) = delete;
8589
~NoNamesGuard() {
8690
if (initialized) {
8791
reset();

aten/src/ATen/core/PythonFallbackKernel.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@ struct StashTLSOnEntryGuard {
3535
StashTLSOnEntryGuard(): saved_(tls_on_entry.value()) {
3636
tls_on_entry = std::nullopt;
3737
}
38+
StashTLSOnEntryGuard(const StashTLSOnEntryGuard&) = delete;
39+
StashTLSOnEntryGuard(StashTLSOnEntryGuard&&) = delete;
40+
StashTLSOnEntryGuard& operator=(const StashTLSOnEntryGuard&) = delete;
41+
StashTLSOnEntryGuard& operator=(StashTLSOnEntryGuard&&) = delete;
3842

3943
~StashTLSOnEntryGuard() {
4044
TORCH_INTERNAL_ASSERT(!tls_on_entry.has_value());

0 commit comments

Comments
 (0)