[llvm] [ADT] Use "= default" in DirectedGraph.h (PR #161628)
Kazu Hirata via llvm-commits
llvm-commits at lists.llvm.org
Wed Oct 1 22:06:36 PDT 2025
https://github.com/kazutakahirata created https://github.com/llvm/llvm-project/pull/161628
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.
>From b2afd576125307af2918fa4f3e2cd9340a651d69 Mon Sep 17 00:00:00 2001
From: Kazu Hirata <kazu at google.com>
Date: Wed, 1 Oct 2025 08:17:12 -0700
Subject: [PATCH] [ADT] Use "= default" in DirectedGraph.h
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.
---
llvm/include/llvm/ADT/DirectedGraph.h | 14 ++++----------
1 file changed, 4 insertions(+), 10 deletions(-)
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(); }
More information about the llvm-commits
mailing list