Skip to content

Commit

Permalink
Add missing clang-tidy fixes for modernize-use-equals-(default|delete) (
Browse files Browse the repository at this point in the history
pytorch#91857)

More clang-tidy for default or deleting more ctors and dtors. This is slightly more efficient and more readable

Pull Request resolved: pytorch#91857
Approved by: https://github.com/ezyang
  • Loading branch information
Skylion007 authored and pytorchmergebot committed Jan 11, 2023
1 parent b9a035c commit 4dcb10e
Show file tree
Hide file tree
Showing 9 changed files with 14 additions and 12 deletions.
6 changes: 3 additions & 3 deletions aten/src/ATen/core/List.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,13 +88,13 @@ class ListElementReference final {

friend void swap<T, Iterator>(ListElementReference&& lhs, ListElementReference&& rhs);

ListElementReference(const ListElementReference&) = delete;
ListElementReference& operator=(const ListElementReference&) = delete;

private:
ListElementReference(Iterator iter)
: iterator_(iter) {}

ListElementReference(const ListElementReference&) = delete;
ListElementReference& operator=(const ListElementReference&) = delete;

// allow moving, but only our friends (i.e. the List class) can move us
ListElementReference(ListElementReference&&) noexcept = default;
ListElementReference& operator=(ListElementReference&& rhs) & noexcept {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class AlignedAllocator {
};

public:
inline AlignedAllocator() noexcept {}
inline AlignedAllocator() noexcept = default;

template <class U>
inline AlignedAllocator(
Expand Down
4 changes: 2 additions & 2 deletions c10/core/DeviceGuard.h
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ class DeviceGuard {
class OptionalDeviceGuard {
public:
/// Create an uninitialized guard. Set the guard later using reset_device.
explicit OptionalDeviceGuard() : guard_() {}
explicit OptionalDeviceGuard() = default;

/// Initialize the guard, setting the current device to the passed Device.
explicit OptionalDeviceGuard(Device device) : guard_(device) {}
Expand Down Expand Up @@ -175,7 +175,7 @@ class OptionalDeviceGuard {
}

private:
impl::InlineOptionalDeviceGuard<impl::VirtualGuardImpl> guard_;
impl::InlineOptionalDeviceGuard<impl::VirtualGuardImpl> guard_{};
};

// Note [Whither the DeviceGuard boilerplate]
Expand Down
4 changes: 2 additions & 2 deletions c10/core/StreamGuard.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ struct StreamGuard {
*/
struct OptionalStreamGuard {
/// Create an uninitialized guard.
explicit OptionalStreamGuard() : guard_() {}
explicit OptionalStreamGuard() = default;

/// Set the current device to the device associated with the passed stream,
/// and set the current stream on that device to the passed stream.
Expand Down Expand Up @@ -136,7 +136,7 @@ struct OptionalStreamGuard {
}

private:
c10::impl::InlineOptionalStreamGuard<impl::VirtualGuardImpl> guard_;
c10::impl::InlineOptionalStreamGuard<impl::VirtualGuardImpl> guard_{};
};

/**
Expand Down
1 change: 1 addition & 0 deletions c10/util/AlignOf.h
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ class AlignerImpl {
T9 t9;
T10 t10;

public:
AlignerImpl() = delete;
};

Expand Down
2 changes: 1 addition & 1 deletion c10/util/SmallVector.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ class C10_API SmallVectorBase {
return std::numeric_limits<Size_T>::max();
}

SmallVectorBase() = delete;
SmallVectorBase(void* FirstEl, size_t TotalCapacity)
: BeginX(FirstEl), Capacity(TotalCapacity) {}

Expand All @@ -80,6 +79,7 @@ class C10_API SmallVectorBase {
void grow_pod(void* FirstEl, size_t MinSize, size_t TSize);

public:
SmallVectorBase() = delete;
size_t size() const {
return Size;
}
Expand Down
2 changes: 1 addition & 1 deletion c10/util/TypeList.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ namespace typelist {
*/
template <class... Items>
struct typelist final {
private:
public:
typelist() = delete; // not for instantiation
};

Expand Down
2 changes: 1 addition & 1 deletion torch/csrc/distributed/autograd/context/container.h
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ class TORCH_API DistAutogradContainer {
std::unordered_map<int64_t, ContextPtr> contexts;
};

DistAutogradContainer();
DistAutogradContainer() = delete;
~DistAutogradContainer() = default;

static DistAutogradContainer& getInstanceInternal();
Expand Down
3 changes: 2 additions & 1 deletion torch/csrc/distributed/rpc/tensorpipe_agent.h
Original file line number Diff line number Diff line change
Expand Up @@ -446,8 +446,9 @@ class TORCH_API TensorPipeAgent : public RpcAgent {
}
}

GroupMembershipLockGuard(const GroupMembershipLockGuard&) = delete;

private:
GroupMembershipLockGuard(const GroupMembershipLockGuard&);
std::mutex& ref_;
bool isStaticGroup_;
};
Expand Down

0 comments on commit 4dcb10e

Please sign in to comment.