[llvm] [ADT] Use "= default" in DirectedGraph.h (PR #161628)

via llvm-commits llvm-commits at lists.llvm.org
Wed Oct 1 22:07:11 PDT 2025


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-llvm-adt

Author: Kazu Hirata (kazutakahirata)

<details>
<summary>Changes</summary>

This patch uses "= default" in copy/move constructors and assignment
operators of DirectedGraph.

Now, the original code:

  DGraphType &operator=(const DGraphType &&G)

is most likely unintended -- a move assignment operator with const
r-value reference.  This patch fixes that.


---
Full diff: https://github.com/llvm/llvm-project/pull/161628.diff


1 Files Affected:

- (modified) llvm/include/llvm/ADT/DirectedGraph.h (+4-10) 


``````````diff
diff --git a/llvm/include/llvm/ADT/DirectedGraph.h b/llvm/include/llvm/ADT/DirectedGraph.h
index 83c0bea6393c4..2a51bc631399c 100644
--- a/llvm/include/llvm/ADT/DirectedGraph.h
+++ b/llvm/include/llvm/ADT/DirectedGraph.h
@@ -181,16 +181,10 @@ template <class NodeType, class EdgeType> class DirectedGraph {
 
   DirectedGraph() = default;
   explicit DirectedGraph(NodeType &N) : Nodes() { addNode(N); }
-  DirectedGraph(const DGraphType &G) : Nodes(G.Nodes) {}
-  DirectedGraph(DGraphType &&RHS) : Nodes(std::move(RHS.Nodes)) {}
-  DGraphType &operator=(const DGraphType &G) {
-    Nodes = G.Nodes;
-    return *this;
-  }
-  DGraphType &operator=(const DGraphType &&G) {
-    Nodes = std::move(G.Nodes);
-    return *this;
-  }
+  DirectedGraph(const DGraphType &G) = default;
+  DirectedGraph(DGraphType &&RHS) = default;
+  DGraphType &operator=(const DGraphType &G) = default;
+  DGraphType &operator=(DGraphType &&G) = default;
 
   const_iterator begin() const { return Nodes.begin(); }
   const_iterator end() const { return Nodes.end(); }

``````````

</details>


https://github.com/llvm/llvm-project/pull/161628


More information about the llvm-commits mailing list