cereal
cereal copied to clipboard
Serialize function fails to be found for templated type when compiling with clang 6
The following code compiles fine in VS2017, but fails in clang 6:
template <class T> class RectT {
public:
T x, y, w, h;
}
typedef RectT<float> Rectf;
template <class Archive> void serialize(Archive& archive, Rectf& rect) {
archive(rect.x, rect.y, rect.w, rect.h);
}
Clang 6 reports that it can't find the serialize
function:
../cereal-1.2.2/include/cereal/cereal.hpp:851:9: error: static_assert failed "cereal could not find any input serialization functions for the provided type and archive combination. \n\n Types must either have a serialize function, load/save pair, or load_minimal/save_minimal pair (you may not mix these). \n Serialize functions generally have the following signature: \n\n template<class Archive> \n void serialize(Archive & ar) \n { \n ar( member1, member2, member3 ); \n } \n\n "
static_assert(traits::detail::count_input_serializers<T, ArchiveType>::value != 0,
^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
../cereal-1.2.2/include/cereal/cereal.hpp:730:15: note: in instantiation of function template specialization 'cereal::InputArchive<cereal::JSONInputArchive, 0>::processImpl<RectT<float>, 0>' requested here
self->processImpl( head );
^
../cereal-1.2.2/include/cereal/cereal.hpp:619:9: note: in instantiation of function template specialization 'cereal::InputArchive<cereal::JSONInputArchive, 0>::process<RectT<float> &>' requested here
process( std::forward<Types>( args )... );
^
../cereal-1.2.2/include/cereal/archives/json.hpp:913:5: note: in instantiation of function template specialization 'cereal::InputArchive<cereal::JSONInputArchive, 0>::operator()<RectT<float> &>' requested here
ar( t.value );
^
../cereal-1.2.2/include/cereal/cereal.hpp:807:9: note: in instantiation of function template specialization 'cereal::load<RectT<float> &>' requested here
CEREAL_LOAD_FUNCTION_NAME(*self, t);
^
../cereal-1.2.2/include/cereal/macros.hpp:85:35: note: expanded from macro 'CEREAL_LOAD_FUNCTION_NAME'
#define CEREAL_LOAD_FUNCTION_NAME load
^
../cereal-1.2.2/include/cereal/cereal.hpp:730:15: note: in instantiation of function template specialization 'cereal::InputArchive<cereal::JSONInputArchive, 0>::processImpl<cereal::NameValuePair<RectT<float> &>, 0>' requested here
self->processImpl( head );
^
../cereal-1.2.2/include/cereal/cereal.hpp:619:9: note: (skipping 11 contexts in backtrace; use -ftemplate-backtrace-limit=0 to see all)
process( std::forward<Types>( args )... );
^
It does work for all other regular structs, why is it failing for a templated type? Since it does work properly in VS2017, that makes me believe my usage of cereal is ok, but maybe I'm wrong. Anyone else has this issue?
FYI, I commented out the static_assert
that checks for the intput/output serializers count in cereal.hpp, and the code compile and runs just fine. For the moment I can work around it this way when __clang__
is defined and leave it enabled for MSVC. But yeah, make kitties sad 😿
That's a really strange error, especially since the types are so simple. I'll have to get an up-to-date clang and see if I can reproduce it and try to debug.
I'm getting this same with glm::vec