diff --git a/llvm/include/llvm/ADT/DirectedGraph.h b/llvm/include/llvm/ADT/DirectedGraph.h --- a/llvm/include/llvm/ADT/DirectedGraph.h +++ b/llvm/include/llvm/ADT/DirectedGraph.h @@ -172,9 +172,9 @@ /// Each edge contains the target node it connects to. template class DirectedGraph { protected: - using NodeListTy = SmallVector; using EdgeListTy = SmallVector; public: + using NodeListTy = SmallVector; using iterator = typename NodeListTy::iterator; using const_iterator = typename NodeListTy::const_iterator; using DGraphType = DirectedGraph; @@ -183,6 +183,7 @@ explicit DirectedGraph(NodeType &N) : Nodes() { addNode(N); } DirectedGraph(const DGraphType &G) : Nodes(G.Nodes) {} DirectedGraph(DGraphType &&RHS) : Nodes(std::move(RHS.Nodes)) {} + explicit DirectedGraph(NodeListTy Nodes) : Nodes(std::move(Nodes)) {} DGraphType &operator=(const DGraphType &G) { Nodes = G.Nodes; return *this; diff --git a/llvm/unittests/ADT/DirectedGraphTest.cpp b/llvm/unittests/ADT/DirectedGraphTest.cpp --- a/llvm/unittests/ADT/DirectedGraphTest.cpp +++ b/llvm/unittests/ADT/DirectedGraphTest.cpp @@ -43,6 +43,7 @@ class DGTestGraph : public DGTestBase { public: DGTestGraph() = default; + using DGTestBase::DGTestBase; ~DGTestGraph(){}; }; @@ -243,8 +244,16 @@ EXPECT_TRUE(EL.empty()); } -TEST(DirectedGraphTest, SCC) { +TEST(DirectedGraphTest, ConstructFromList) { + DGTestNode N1, N2; + DGTestGraph::NodeListTy nodes{&N1, &N2}; + DGTestGraph graph(std::move(nodes)); + + EXPECT_FALSE(graph.addNode(N1)); + EXPECT_FALSE(graph.addNode(N2)); +} +TEST(DirectedGraphTest, SCC) { DGTestGraph DG; DGTestNode N1, N2, N3, N4; DGTestEdge E1(N1), E2(N2), E3(N3), E4(N4);