7

Got a savage few compile errors while trying to use Boost.Graph. The error is a regression as it is not present when compiling 1.55.0. I've dug a bit but can't fix it, does anyone know what is going wrong here?

Notes: Using the -std=c++0x compile flag

Code that will generate the errors.

#include "boost/graph/adjacency_list.hpp"

int main(int argc, char** argv)
{
  using boost::adjacency_list;
  using boost::vecS;
  using boost::directedS;
  typedef adjacency_list<vecS, vecS, directedS, boost::default_color_type> Graph;

  std::vector< std::pair<int, int> > testVec;
  auto graph = Graph( begin(testVec), end(testVec), testVec.size());

  return 0;
}

Errors copied out of my IDE

/usr/include/c++/4.6/bits/vector.tcc:319: error: use of deleted function ‘boost::detail::stored_edge_property::self& boost::detail::stored_edge_property::operator=(boost::detail::stored_edge_property::self&&) [with Vertex = long unsigned int, Property = boost::no_property, boost::detail::stored_edge_property::self = boost::detail::stored_edge_property]’

.../boost/boost/graph/detail/adjacency_list.hpp:318: error: ‘boost::detail::stored_edge_property::self& boost::detail::stored_edge_property::operator=(boost::detail::stored_edge_property::self&&) [with Vertex = long unsigned int, Property = boost::no_property, boost::detail::stored_edge_property::self = boost::detail::stored_edge_property]’ is implicitly deleted because the default definition would be ill-formed:

.../boost/boost/graph/detail/adjacency_list.hpp:318: error: base ‘boost::detail::stored_edge’ does not have a move assignment operator or trivial copy assignment operator

/usr/include/c++/4.6/bits/stl_algobase.h:546: error: use of deleted function ‘boost::detail::stored_edge_property::self& boost::detail::stored_edge_property::operator=(boost::detail::stored_edge_property::self&&) [with Vertex = long unsigned int, Property = boost::no_property, boost::detail::stored_edge_property::self = boost::detail::stored_edge_property]’

4
  • Have you looked at the diffs for stored_edge and adjacency_list.hpp from 1.55 to 1.56? The answer is probably in there. Aug 20, 2014 at 3:33
  • Not a bad idea, I'll have a look and see what's different.
    – radman
    Aug 20, 2014 at 4:02
  • 2
    bug logged on the boost bug tracker. It also should be noted that the compile errors do not occur on g++4.7 or 4.8, this is a g++4.6 specific problem.
    – radman
    Aug 20, 2014 at 5:13
  • @radman The bug is happening for me with gcc 4.8.5 on Ubuntu with boost 1.61.
    – TonySalimi
    Jun 11, 2019 at 16:23

1 Answer 1

6

It appears that the implementation of stored_edge_property (a under-the-hood class to store edge properties) was updated for C++11 rvalue references between the version 1.55 to 1.56 (you can see it clearly by diff'ing the files). It appears that they forgot to provide a move-assignment operator for its base class stored_edge (and the default one is implicitly disabled by the presence of a copy-assignment operator).

This is definitely a bug and should be reported to Boost. I remember that they made a virtually identical mistake with shared_ptr around the 1.48 version. I guess people don't always learn from their own mistakes. The fix is trivial, but this really should have been caught before release (it seems like a very easy bug to catch in a unit-test). Please report your findings to their bug tracker.

N.B.: I use BGL a lot, but I have learned to distrust their adjacency_list implementation, especially after looking through it extensively. I now use my own implementation of it (see here) which cuts through a lot of the fat of the monstrous implementation that the BGL carries around.

14
  • That two different Boost libraries made a similar mistake a year or two apart is not that surprising, since they're probably written by two separate groups of people. Aug 20, 2014 at 4:49
  • Thanks, I'd actually just worked most of this out and was coming back to explain it. A point of clarification; in detail/adjacency_list.hpp:319-21 the default specifier has been used for stored_edge_property's move operators, you're saying this fails to work because its base doesn't have a move operator?
    – radman
    Aug 20, 2014 at 5:02
  • It fails to work because its base class, called stored_edge, has a copy-assignment operator, which, by C++11 rules, disables the default (implicit) move-assignment operator for that class. Without a move-assignment operator in the base class, the compiler cannot generate the default move-assignment operator for the derived class. The fix should be as simple as defining a move-assignment operator in the base class similar to the copy-assignment operator it already has (or it could even be an explicitly defaulted move-assignment operator too, I think). Aug 20, 2014 at 5:20
  • 1
    Thanks Mikael, defaulting the move assignment and move constructor in stored_edge did the trick. My previous solution was to change the condition on :302 to be 4.7 and below to exclude 4.6, expedient but not a proper fix. I've also verified this doesn't occur on 4.7 or 4.8, any insight into why that might be?
    – radman
    Aug 20, 2014 at 5:39
  • 1
    @radman I believe that it works on 4.7 and 4.8 because the compiler can pick the copy-assignment operator from stored_edge instead of the implicitly disabled move-assignment operator. I'm not sure what the rules are for that, but I'm sure that the move-assign is disabled by the presence of the copy-assign, and I suspect that the compiler is allowed to pick the base-class copy-assign instead of the move-assign to implement the default derived-class move-assignment. My guess would be that 4.6 had the "disabling rule", but could not pick up the base-class copy-assign as an alternative. Aug 20, 2014 at 17:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.