Boost Graph: vertex class has no copy constructor
Hi, I'm using the Boost Graph library to construct a directed graph: typedef boost::directed_graph<BasicBlock> Graph; The vertex class, "BasicBlock", is not my own; it comes from the LLVM project. Unfortunately, the declaration above causes a slew of compiler errors (see below) that appear to be related to BasicBlock's copy constructor. Sure enough, I checked BasicBlock.h, and its copy constructor is declared private and is not even implemented. There appears to be some sort of design issue that prevents this class from having a copy constructor. Is there some workaround for this on the Boost Graph side, or must vertex classes always have a copy constructor? Thanks, Trevor /Users/twharmon/Development/boost_1_42_0/boost/pending/property.hpp: In constructor ‘boost::property<Tag, T, Base>::property(const T&) [with Tag = boost::vertex_bundle_t, T = llvm::BasicBlock, Base = boost::no_property]’: Clepsydra.cpp:46: instantiated from here /Users/twharmon/Development/LLVM/llvm-2.7/llvm-2.7-src/include/llvm/ BasicBlock.h:81: error: ‘llvm::BasicBlock::BasicBlock(const llvm::BasicBlock&)’ is private /Users/twharmon/Development/boost_1_42_0/boost/pending/property.hpp: 31: error: within this context /Users/twharmon/Development/boost_1_42_0/boost/pending/property.hpp: In copy constructor ‘boost::property<boost::vertex_bundle_t, llvm::BasicBlock, boost::no_property>::property(const boost::property<boost::vertex_bundle_t, llvm::BasicBlock, boost::no_property>&)’: /Users/twharmon/Development/boost_1_42_0/boost/pending/property.hpp: 22: instantiated from ‘typename boost::adjacency_list<boost::listS, boost::listS, boost::bidirectionalS, boost::property<boost::vertex_index_t, unsigned int, typename boost::graph_detail::vertex_prop<Prop>::type>, boost::property<boost::edge_index_t, unsigned int, typename boost::graph_detail::edge_prop<EdgeProp>::type>, GraphProp, boost::listS>::vertex_descriptor boost::directed_graph<VertexProp, EdgeProp, GraphProp>::add_vertex(const typename boost::graph_detail::vertex_prop<Prop>::type&) [with VertexProp = llvm::BasicBlock, EdgeProp = boost::no_property, GraphProp = boost::no_property]’ /Users/twharmon/Development/boost_1_42_0/boost/graph/ directed_graph.hpp:454: instantiated from ‘typename boost::directed_graph<VertexProp, EdgeProp, GraphProp>::vertex_descriptor boost::add_vertex(const typename boost::directed_graph<VertexProp, EdgeProp, GraphProp>::vertex_property_type&, boost::directed_graph<VP, EP, GP>&) [with VP = llvm::BasicBlock, EP = boost::no_property, GP = boost::no_property]’ Clepsydra.cpp:46: instantiated from here /Users/twharmon/Development/LLVM/llvm-2.7/llvm-2.7-src/include/llvm/ BasicBlock.h:81: error: ‘llvm::BasicBlock::BasicBlock(const llvm::BasicBlock&)’ is private /Users/twharmon/Development/boost_1_42_0/boost/pending/property.hpp: 22: error: within this context cc1plus: warnings being treated as errors /Users/twharmon/Development/boost_1_42_0/boost/pending/property.hpp: In copy constructor ‘boost::property<boost::vertex_index_t, unsigned int, boost::property<boost::vertex_bundle_t, llvm::BasicBlock, boost::no_property> >::property(const boost::property<boost::vertex_index_t, unsigned int, boost::property<boost::vertex_bundle_t, llvm::BasicBlock, boost::no_property> >&)’: /Users/twharmon/Development/boost_1_42_0/boost/pending/property.hpp: 22: warning: synthesized method ‘boost::property<boost::vertex_bundle_t, llvm::BasicBlock, boost::no_property>::property(const boost::property<boost::vertex_bundle_t, llvm::BasicBlock, boost::no_property>&)’ first required here /Users/twharmon/Development/boost_1_42_0/boost/graph/ directed_graph.hpp: In member function ‘typename boost::adjacency_list<boost::listS, boost::listS, boost::bidirectionalS, boost::property<boost::vertex_index_t, unsigned int, typename boost::graph_detail::vertex_prop<Prop>::type>, boost::property<boost::edge_index_t, unsigned int, typename boost::graph_detail::edge_prop<EdgeProp>::type>, GraphProp, boost::listS>::vertex_descriptor boost::directed_graph<VertexProp, EdgeProp, GraphProp>::add_vertex(const typename boost::graph_detail::vertex_prop<Prop>::type&) [with VertexProp = llvm::BasicBlock, EdgeProp = boost::no_property, GraphProp = boost::no_property]’: /Users/twharmon/Development/boost_1_42_0/boost/graph/ directed_graph.hpp:154: warning: synthesized method ‘boost::property<boost::vertex_index_t, unsigned int, boost::property<boost::vertex_bundle_t, llvm::BasicBlock, boost::no_property> >::property(const boost::property<boost::vertex_index_t, unsigned int, boost::property<boost::vertex_bundle_t, llvm::BasicBlock, boost::no_property> >&)’ first required here
Hi Trevor, Unfortunately, the declaration above causes a slew of compiler errors (see
below) that appear to be related to BasicBlock's copy constructor. Sure enough, I checked BasicBlock.h, and its copy constructor is declared private and is not even implemented. There appears to be some sort of design issue that prevents this class from having a copy constructor.
Is there some workaround for this on the Boost Graph side, or must vertex classes always have a copy constructor?
The "easy" workaround is to simply have the graph refer to BasicBlock by pointer instead of actually owning it. Pointers are definitely default and copy constructible :) Otherwise, those property classes are largely required to be copy and/or default constructible. I might caution you about using directed_graph. It's built over adjacency_list<listS, listS, ...> so it might not be usable quite the same way that most of the documentation is listed. Also, since I wrote the class, if you have any problems with it, please let me know so I can fix them! Andrew Sutton andrew.n.sutton@gmail.com
On Mar 26, 2010, at 5:42 AM, Andrew Sutton wrote:
The "easy" workaround is to simply have the graph refer to BasicBlock by pointer instead of actually owning it. Pointers are definitely default and copy constructible :)
Yes, I had tried that, and the pointers are added to the graph okay using add_vertex, but when I try to pull them out using, say, graph[0], my program segfaults. I have no idea what I'm doing wrong.
I might caution you about using directed_graph. It's built over adjacency_list<listS, listS, ...> so it might not be usable quite the same way that most of the documentation is listed.
So instead of: typedef directed_graph<BasicBlock*> TimingGraph; I should do maybe: typedef adjacency_list<vecS, vecS, directedS, BasicBlock*> TimingGraph; ? Trevor
The "easy" workaround is to simply have the graph refer to BasicBlock by
pointer instead of actually owning it. Pointers are definitely default and copy constructible :)
Yes, I had tried that, and the pointers are added to the graph okay using add_vertex, but when I try to pull them out using, say, graph[0], my program segfaults. I have no idea what I'm doing wrong.
It's not surprising that graph[0] crashes for directed_graph; it's vertex descriptors are actually list iterators. It turns out that 0 is an implicit constructor for directed_graph<...>::null_vertex(). The (current BGL) documentation doesn't spell this out very well, and almost none of the examples demonstrate this fact. I think you could use: graph[vertex(g, 0)] but that might be O(n). I should do maybe:
typedef adjacency_list<vecS, vecS, directedS, BasicBlock*> TimingGraph;
If you're not going to remove vertices, then that's probably a good bet. I forget if this is good for removing edges also. I'm guessing "no". Andrew Sutton andrew.n.sutton@gmail.com
On Mar 26, 2010, at 11:36 AM, Trevor Harmon wrote:
Yes, I had tried that, and the pointers are added to the graph okay using add_vertex, but when I try to pull them out using, say, graph[0], my program segfaults. I have no idea what I'm doing wrong.
Never mind the above; I was doing something dumb. One of the graphs I had created was empty, and so graph[0] was being called on an empty graph. Still, I'm not sure why that would actually cause a segfault. In fact, it wasn't the call that was causing the segfault but rather the assignment: graph[0]; // okay void foo* = graph[0]; // bus error Anyway, at least it's working now... Trevor
participants (3)
-
Andrew Sutton
-
Trevor Harmon
-
Trevor Harmon