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

Serialize function fails to be found for templated type when compiling with clang 6 #516

Open
gouletr opened this issue Aug 6, 2018 · 3 comments

Comments

@gouletr
Copy link
Contributor

gouletr commented Aug 6, 2018

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?

@gouletr
Copy link
Contributor Author

gouletr commented Aug 13, 2018

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 😿

@AzothAmmo
Copy link
Contributor

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.

@BinaryAura
Copy link

I'm getting this same with glm::vec. clang as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants