From 1c295e68305ba0be4d5a63be8efe5a68ac1dab1e Mon Sep 17 00:00:00 2001 From: Anthony Van Herrewege Date: Mon, 3 Feb 2025 15:36:24 +0100 Subject: [PATCH] Ensure named_graph base class is initialized before accessing it --- include/boost/graph/adjacency_list.hpp | 17 ++++++++++------- test/named_vertices_test.cpp | 3 +++ 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/include/boost/graph/adjacency_list.hpp b/include/boost/graph/adjacency_list.hpp index e5050b5b..113143a7 100644 --- a/include/boost/graph/adjacency_list.hpp +++ b/include/boost/graph/adjacency_list.hpp @@ -267,18 +267,21 @@ template < class OutEdgeListS = vecS, // a Sequence or an AssociativeContainer class EdgeProperty = no_property, class GraphProperty = no_property, class EdgeListS = listS > class adjacency_list -: public detail::adj_list_gen< - adjacency_list< OutEdgeListS, VertexListS, DirectedS, VertexProperty, - EdgeProperty, GraphProperty, EdgeListS >, - VertexListS, OutEdgeListS, DirectedS, VertexProperty, EdgeProperty, - GraphProperty, EdgeListS >::type, - // Support for named vertices +: // Support for named vertices + // This needs to be inherited from first to ensure it's initialized before the + // "base" (i.e. detail::adj_list_gen), because the "base" might indirectly + // call functions on it during its construction. public graph::maybe_named_graph< adjacency_list< OutEdgeListS, VertexListS, DirectedS, VertexProperty, EdgeProperty, GraphProperty, EdgeListS >, typename adjacency_list_traits< OutEdgeListS, VertexListS, DirectedS, EdgeListS >::vertex_descriptor, - VertexProperty > + VertexProperty >, + public detail::adj_list_gen< + adjacency_list< OutEdgeListS, VertexListS, DirectedS, VertexProperty, + EdgeProperty, GraphProperty, EdgeListS >, + VertexListS, OutEdgeListS, DirectedS, VertexProperty, EdgeProperty, + GraphProperty, EdgeListS >::type { public: typedef GraphProperty graph_property_type; diff --git a/test/named_vertices_test.cpp b/test/named_vertices_test.cpp index 69ba7f18..4d13785a 100644 --- a/test/named_vertices_test.cpp +++ b/test/named_vertices_test.cpp @@ -91,5 +91,8 @@ int main(int, char*[]) BOOST_TEST(map[*find_vertex("Cincinnatti", map)].population == -1); + // Ensure copy constructor properly initializes base classes. + BOOST_TEST_NO_THROW(RoadMap{map}); + return boost::report_errors(); }