Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

143 fix virtual serialization with abstract classes in hierarchy #144

Merged
merged 7 commits into from
Oct 19, 2020
6 changes: 4 additions & 2 deletions src/checkpoint/dispatch/vrt/serialize_instantiator.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ struct InstantiateIfPossible<
ObjT,
SerializerT,
typename std::enable_if_t<
SerializableTraits<ObjT, SerializerT>::is_serializable
SerializableTraits<ObjT, SerializerT>::has_serialize_function or
SerializableTraits<ObjT, SerializerT>::is_bytecopyable
>
> {
static void registerIt() {
Expand All @@ -82,7 +83,8 @@ struct InstantiateIfPossible<
ObjT,
SerializerT,
typename std::enable_if_t<
not SerializableTraits<ObjT, SerializerT>::is_serializable
not (SerializableTraits<ObjT, SerializerT>::has_serialize_function or
SerializableTraits<ObjT, SerializerT>::is_bytecopyable)
>
> {
static void registerIt() {
Expand Down
35 changes: 35 additions & 0 deletions tests/unit/test_footprinter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -529,4 +529,39 @@ TEST_F(TestFootprinter, test_virtual_serialize) {
}
}

struct HolderBase {
checkpoint_virtual_serialize_root()

virtual ~HolderBase() = default;

template <typename Serializer>
void serialize(Serializer& s) {}
};

template <typename ObjT>
struct HolderObjBase : HolderBase {
checkpoint_virtual_serialize_derived_from(HolderBase)

virtual ObjT* get() = 0;

template <typename Serializer>
void serialize(Serializer& s) {}
};

template <typename ObjT>
struct HolderBasic final : HolderObjBase<ObjT> {
checkpoint_virtual_serialize_derived_from(HolderObjBase<ObjT>)

ObjT* get() override { return obj_; }
ObjT* obj_ = nullptr;

template <typename Serializer>
void serialize(Serializer& s) {}
};

TEST_F(TestFootprinter, test_virtual_serialize_templated) {
std::unique_ptr<HolderBase> ptr = std::make_unique<HolderBasic<int>>();
checkpoint::getMemoryFootprint(ptr);
}

}}} // end namespace checkpoint::tests::unit