[llvm] [ADT] Achieve the "Rule of Zero" in DGNode (PR #165190)
Kazu Hirata via llvm-commits
llvm-commits at lists.llvm.org
Sun Oct 26 20:36:31 PDT 2025
https://github.com/kazutakahirata created https://github.com/llvm/llvm-project/pull/165190
This patch achieves the "Rule of Zero" in DGNode by removing the
copy/move constructors and copy/move assignment operators.
Note that the code being deleted does a couple of unusual things that
are most likely oversight:
- The copy constructor with "explicit" is highly unusual. This means
that we allow "DGNode<N, E> A(B);" but disallow
"DGNode<N, E> A = B;".
- The move assignment operator with const r-value reference is also
unusual, especially given that the move constructor is correctly
implemented.
>From 3ff4b53385cc26c39f5cfcbf571e11b41cde9f7f Mon Sep 17 00:00:00 2001
From: Kazu Hirata <kazu at google.com>
Date: Sun, 26 Oct 2025 18:23:22 -0700
Subject: [PATCH] [ADT] Achieve the "Rule of Zero" in DGNode
This patch achieves the "Rule of Zero" in DGNode by removing the
copy/move constructors and copy/move assignment operators.
Note that the code being deleted does a couple of unusual things that
are most likely oversight:
- The copy constructor with "explicit" is highly unusual. This means
that we allow "DGNode<N, E> A(B);" but disallow
"DGNode<N, E> A = B;".
- The move assignment operator with const r-value reference is also
unusual, especially given that the move constructor is correctly
implemented.
---
llvm/include/llvm/ADT/DirectedGraph.h | 12 ------------
1 file changed, 12 deletions(-)
diff --git a/llvm/include/llvm/ADT/DirectedGraph.h b/llvm/include/llvm/ADT/DirectedGraph.h
index fb6b180f77e6b..fe7c9e51cbd9a 100644
--- a/llvm/include/llvm/ADT/DirectedGraph.h
+++ b/llvm/include/llvm/ADT/DirectedGraph.h
@@ -80,18 +80,6 @@ template <class NodeType, class EdgeType> class DGNode {
explicit DGNode(EdgeType &E) : Edges() { Edges.insert(&E); }
DGNode() = default;
- explicit DGNode(const DGNode<NodeType, EdgeType> &N) : Edges(N.Edges) {}
- DGNode(DGNode<NodeType, EdgeType> &&N) : Edges(std::move(N.Edges)) {}
-
- DGNode<NodeType, EdgeType> &operator=(const DGNode<NodeType, EdgeType> &N) {
- Edges = N.Edges;
- return *this;
- }
- DGNode<NodeType, EdgeType> &operator=(const DGNode<NodeType, EdgeType> &&N) {
- Edges = std::move(N.Edges);
- return *this;
- }
-
/// Static polymorphism: delegate implementation (via isEqualTo) to the
/// derived class.
friend bool operator==(const NodeType &M, const NodeType &N) {
More information about the llvm-commits
mailing list