Skip to content

CEREAL_REGISTER_POLYMORPHIC_RELATION fails to register relation under VS2015 #356

Closed
@ChrisBFX

Description

I get the "Trying to save a registered polymorphic type with an unregistered polymorphic cast. " exception when I want to serialize a base-class which has multiple derived classes, even when the relations are registered via CEREAL_REGISTER_POLYMORPHIC_RELATION.
It seems like PolymorphicVirtualCaster() doesn't registers all relations.

I also tested the develop branch which has the same behavior. (it works fine under gcc 4.9 though).

For testing I added:

CEREAL_REGISTER_TYPE(Base)
struct YourType2 : public YourType
{
	

	template<class Archive>
	void save(Archive & ar) const
	{
		std::cout << "Saving YourType2" << std::endl;
	}

	template<class Archive>
	void load(Archive & ar)
	{
		std::cout << "Loading YourType2" << std::endl;
	}
};

CEREAL_REGISTER_TYPE(YourType2)
CEREAL_REGISTER_POLYMORPHIC_RELATION(YourType, YourType2)


struct YourType3 : public YourType
{
	

	template<class Archive>
	void save(Archive & ar) const
	{
		std::cout << "Saving YourType3" << std::endl;
	}

	template<class Archive>
	void load(Archive & ar)
	{
		std::cout << "Loading YourType3" << std::endl;
	}
};

CEREAL_REGISTER_TYPE(YourType3)
CEREAL_REGISTER_POLYMORPHIC_RELATION(YourType, YourType3) 

to the rtti test, and saved instances of YourType2 and YourType3.

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions