Skip to content

Conversation

kazutakahirata
Copy link
Contributor

@kazutakahirata kazutakahirata commented Oct 2, 2025

This patch drops user copy/move constructors and assignment operators
of DirectedGraph to adhere to the Rule of Zero.

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.

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.
@llvmbot
Copy link
Member

llvmbot commented Oct 2, 2025

@llvm/pr-subscribers-llvm-adt

Author: Kazu Hirata (kazutakahirata)

Changes

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 --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(); }

@zwuis
Copy link
Contributor

zwuis commented Oct 2, 2025

Can we just remove these functions, following rule of zero?

@kazutakahirata
Copy link
Contributor Author

Can we just remove these functions, following rule of zero?

Good point! Fixed. Thanks!

@kazutakahirata kazutakahirata merged commit 7eb5c08 into llvm:main Oct 2, 2025
9 checks passed
@kazutakahirata kazutakahirata deleted the cleanup_20251001_ADT_DirectedGraph branch October 2, 2025 16:29
mahesh-attarde pushed a commit to mahesh-attarde/llvm-project that referenced this pull request Oct 3, 2025
This patch drops user copy/move constructors and assignment operators
of DirectedGraph to adhere to the Rule of Zero.

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants