Question:
#include <boost/multi_index_container.hpp>
#include <boost/multi_index/hashed_index.hpp>
#include <boost/multi_index/mem_fun.hpp>
namespace mi = boost::multi_index;
namespace vo {
class Statable {};
class Entity : virtual public Statable {};
} /* namespace vo */
class Statable : virtual public vo::Statable {};
class Entity
: virtual public vo::Entity
, public Statable
{
std::string name_;
public:
std::string const& name() const { return name_; }
private:
typedef mi::multi_index_container <
Entity*
, mi::indexed_by<mi::hashed_unique<mi::const_mem_fun<Entity, std::string const&, &Entity::name> > >
> nested_objects_t;
nested_objects_t nested_objects_;
};
Good day! With such a code architecture (this is a simplified example, of course), compilation breaks with an error:
Error C1001 An internal error has occurred in the compiler
Trial and error revealed that the problem is in the line:
mi::hashed_unique<mi::const_mem_fun<Entity, std::string const&, &Entity::name> >
This problem only occurs when virtual inheritance is present! Those. if now Entity is made only a successor from ::Statable (remove virtual public vo::Entity), and in turn make it a regular successor from vo::Statable (without virtual public), then the error will disappear.
Also, the error will disappear if you just take out the typedef outside the Entity class!
Why is this happening, I can not understand in any way?
PS Tried in VS2010, VS2012, VS2015 with various boost versions from 1.33 to 1.68
Answer:
I reproduced this error even in a simpler example. It is enough to have virtual inheritance in the top class Entity
for it to occur. The base class is enough one, any.
However, after adding
#pragma pointers_to_members(full_generality)
the error is gone. I haven't checked if this results in the full functionality of your code, however, when dealing with pointers to class members under multiple and virtual inheritance conditions in MSVC++, I would recommend always setting these options to the most "safe" option.