[graph] Problem compiling simple graph code with recent g++

I'm having some problems with the Boost Graph library in 1.42.
Specifically, if I include the graph concepts header before declaring my
overloads of vertices, out_edges et al, the compiler can't see my
overloads. I've produced a small-ish test case (below) which doesn't
compile with g++ 4.4.3. (It's not supposed to link...)
In file included from test.cpp:3:
/home/srk31/opt/include/boost/graph/graph_concepts.hpp: In destructor ?boost::concepts::VertexListGraph<G>::~VertexListGraph() [with G = Gr]?:
/home/srk31/opt/include/boost/graph/graph_concepts.hpp:166: instantiated from ?static void boost::concept::requirement<Model>::failed() [with Model = boost::concepts::VertexListGraphConcept<Gr>]?
/home/srk31/opt/include/boost/concept_check.hpp:43: instantiated from ?void boost::function_requires(Model*) [with Model = boost::concepts::VertexListGraphConcept<Gr>]?
test.cpp:49: instantiated from here
/home/srk31/opt/include/boost/graph/graph_concepts.hpp:187: error: no matching function for call to ?vertices(Gr&)?
/home/srk31/opt/include/boost/graph/graph_concepts.hpp: In member function ?void boost::concepts::VertexListGraph<G>::const_constraints(const G&) [with G = Gr]?:
/home/srk31/opt/include/boost/graph/graph_concepts.hpp:189: instantiated from ?boost::concepts::VertexListGraph<G>::~VertexListGraph() [with G = Gr]?
/home/srk31/opt/include/boost/graph/graph_concepts.hpp:166: instantiated from ?static void boost::concept::requirement<Model>::failed() [with Model = boost::concepts::VertexListGraphConcept<Gr>]?
/home/srk31/opt/include/boost/concept_check.hpp:43: instantiated from ?void boost::function_requires(Model*) [with Model = boost::concepts::VertexListGraphConcept<Gr>]?
test.cpp:49: instantiated from here
/home/srk31/opt/include/boost/graph/graph_concepts.hpp:201: error: no matching function for call to ?vertices(const Gr&)?
What's odd is that if I move the #include of
boost/graph/graph_concepts.hpp to *below* my overloads, it does work.
However, that code reordering is not an option in the actual context
where I'm having this problem.
Can anyone see anything wrong with my code, or verify that they do or
don't see the same problem? I'm thinking it's a compiler bug but am not
sure... will file it in gcc bugzilla if I'm not proved wrong here. It
does build successfully with g++ 4.1.2. If anyone knows a workaround, or
has other suggestions, I'd be very grateful. Anyway, thanks for reading!
Stephen
#include <utility>
#include

On Thu, 18 Mar 2010, Stephen Kell wrote:
I'm having some problems with the Boost Graph library in 1.42. Specifically, if I include the graph concepts header before declaring my overloads of vertices, out_edges et al, the compiler can't see my overloads. I've produced a small-ish test case (below) which doesn't compile with g++ 4.4.3. (It's not supposed to link...)
In file included from test.cpp:3: /home/srk31/opt/include/boost/graph/graph_concepts.hpp: In destructor ?boost::concepts::VertexListGraph<G>::~VertexListGraph() [with G = Gr]?: /home/srk31/opt/include/boost/graph/graph_concepts.hpp:166: instantiated from ?static void boost::concept::requirement<Model>::failed() [with Model = boost::concepts::VertexListGraphConcept<Gr>]? /home/srk31/opt/include/boost/concept_check.hpp:43: instantiated from ?void boost::function_requires(Model*) [with Model = boost::concepts::VertexListGraphConcept<Gr>]? test.cpp:49: instantiated from here /home/srk31/opt/include/boost/graph/graph_concepts.hpp:187: error: no matching function for call to ?vertices(Gr&)? /home/srk31/opt/include/boost/graph/graph_concepts.hpp: In member function ?void boost::concepts::VertexListGraph<G>::const_constraints(const G&) [with G = Gr]?: /home/srk31/opt/include/boost/graph/graph_concepts.hpp:189: instantiated from ?boost::concepts::VertexListGraph<G>::~VertexListGraph() [with G = Gr]? /home/srk31/opt/include/boost/graph/graph_concepts.hpp:166: instantiated from ?static void boost::concept::requirement<Model>::failed() [with Model = boost::concepts::VertexListGraphConcept<Gr>]? /home/srk31/opt/include/boost/concept_check.hpp:43: instantiated from ?void boost::function_requires(Model*) [with Model = boost::concepts::VertexListGraphConcept<Gr>]? test.cpp:49: instantiated from here /home/srk31/opt/include/boost/graph/graph_concepts.hpp:201: error: no matching function for call to ?vertices(const Gr&)?
What's odd is that if I move the #include of boost/graph/graph_concepts.hpp to *below* my overloads, it does work. However, that code reordering is not an option in the actual context where I'm having this problem.
Can anyone see anything wrong with my code, or verify that they do or don't see the same problem? I'm thinking it's a compiler bug but am not sure... will file it in gcc bugzilla if I'm not proved wrong here. It does build successfully with g++ 4.1.2. If anyone knows a workaround, or has other suggestions, I'd be very grateful. Anyway, thanks for reading!
Could you please try moving your functions outside the boost namespace? Whether those are found depends on exactly where the caller is (I don't think calls from boost::concept will find things in boost:: by default), while having them in the same namespace as Gr would ensure that they are found by ADL. -- Jeremiah Willcock

Could you please try moving your functions outside the boost namespace? Whether those are found depends on exactly where the caller is (I don't think calls from boost::concept will find things in boost:: by default), while having them in the same namespace as Gr would ensure that they are found by ADL.
Thanks very much for this response. Indeed, it compiles if I move my overloads into the same namespace as Gr. I'm not sure why I didn't think of trying that! Many thanks for the fix. I still find it a bit surprising... I guess I need to re-read the ADL rules. :-) I'm pretty sure I've seen some examples in the online documentation which don't follow this pattern (e.g. the LEDA graph adaptation tutorial) but no doubt there is some other intricacy of name lookup that makes them work.... Thanks again! Stephen
participants (2)
-
Jeremiah Willcock
-
Stephen Kell