Loki-Astari / ThorsMongo

C++ MongoDB API and BSON/JSON Serialization library
GNU General Public License v3.0
316 stars 71 forks source link

Make Trait does not work for types with static members with non-standard types #67

Closed gladijos closed 1 year ago

gladijos commented 4 years ago

When I make trait for type with static memder of standard type (int, double, etc.) it works fine. When I make trait for type1 with static memder of non-standard type2 (my own class), even I previously make traits for type2, making trait fore type1 does not work.

A minimal compilable example of that features the bug.

main.cpp

include

include <ThorSerialize/JsonThor.h>

include <ThorSerialize/SerUtil.h>

struct Type1 { int a; }; struct Type2 { static int b; static Type1 c; };

ThorsAnvil_MakeTrait(Type1, a); ThorsAnvil_MakeTrait(Type2, b, c);

using ThorsAnvil::Serialize::jsonExport; using ThorsAnvil::Serialize::jsonImport; int main(int argc, char* argv[]) { std::fstream fileStream; Type2 entity; fileStream >> jsonImport(entity); fileStream << jsonExport(entity); return 0; }

A description of how to build and run the code

g++ -std=c++14 -I/usr/local/include -L/usr/local/lib -lThorSerialize17 main.cpp
cat stuff | ./a.out

Expected behavior

compile OK

Environment:

Additional context

I got compile-time error In file included from /usr/local/include/ThorSerialize/Serialize.h:429:0, from /usr/local/include/ThorSerialize/JsonParser.h:20, from /usr/local/include/ThorSerialize/JsonThor.h:14, from main.cpp:2: /usr/local/include/ThorSerialize/Serialize.tpp: In instantiation of ‘ThorsAnvil::Serialize::DeSerializeMember<T, M> ThorsAnvil::Serialize::make_DeSerializeMember(ThorsAnvil::Serialize::DeSerializer&, ThorsAnvil::Serialize::ParserInterface&, const string&, T&, const std::pair<const char, M>&) [with T = Type2; M = Type1; std::cxx11::string = std::cxx11::basic_string]’: /usr/local/include/ThorSerialize/Serialize.tpp:508:73: required from ‘bool ThorsAnvil::Serialize::DeSerializer::scanEachMember(const string&, T&, const Members&, std::index_sequence<Seq ...>&) [with T = Type2; Members = std::tuple<std::pair<const char, int>, std::pair<const char, Type1> >; long unsigned int ...Seq = {0, 1}; std::cxx11::string = std::cxx11::basic_string; std::index_sequence<Seq ...> = std::integer_sequence<long unsigned int, 0, 1>]’ /usr/local/include/ThorSerialize/Serialize.tpp:515:95: required from ‘bool ThorsAnvil::Serialize::DeSerializer::scanMembers(const string&, T&, const std::tuple<_Elements ...>&) [with T = Type2; Members = {std::pair<const char, int>, std::pair<const char, Type1>}; std::cxx11::string = std::cxx11::basic_string]’ /usr/local/include/ThorSerialize/Serialize.tpp:531:17: required from ‘bool ThorsAnvil::Serialize::DeSerializer::scanObjectMembers(const I&, T&) [with T = Type2; I = std::__cxx11::basic_string]’ /usr/local/include/ThorSerialize/Serialize.tpp:196:21: required from ‘void ThorsAnvil::Serialize::DeSerializationForBlock<traitType, T>::scanObject(T&) [with ThorsAnvil::Serialize::TraitType traitType = (ThorsAnvil::Serialize::TraitType)3; T = Type2]’ /usr/local/include/ThorSerialize/Serialize.tpp:541:9: required from ‘void ThorsAnvil::Serialize::DeSerializer::parse(T&) [with T = Type2]’ /usr/local/include/ThorSerialize/Importer.h:35:17: required from ‘std::istream& ThorsAnvil::Serialize::operator>>(std::istream&, const ThorsAnvil::Serialize::Importer<ThorsAnvil::Serialize::Json, Type2>&)’ main.cpp:24:34: required from here /usr/local/include/ThorSerialize/Serialize.tpp:494:12: error: no matching function for call to ‘ThorsAnvil::Serialize::DeSerializeMember<Type2, Type1, (ThorsAnvil::Serialize::TraitType)3>::DeSerializeMember(ThorsAnvil::Serialize::DeSerializer&, ThorsAnvil::Serialize::ParserInterface&, const string&, Type2&, const std::pair<const char, Type1>&)’ return DeSerializeMember<T, M>(parent, parser, key, object, memberInfo); ^~~~~~~~~~~~~~~~ /usr/local/include/ThorSerialize/Serialize.tpp:450:1: note: candidate: ThorsAnvil::Serialize::DeSerializeMemberContainer<T, M>::DeSerializeMemberContainer(ThorsAnvil::Serialize::DeSerializer&, ThorsAnvil::Serialize::ParserInterface&, const string&, T&, const std::pair<const char, M T::>&) [with T = Type2; M = Type1; std::cxx11::string = std::cxx11::basic_string] DeSerializeMemberContainer<T, M>::DeSerializeMemberContainer(DeSerializer&, ParserInterface& parser, std::string const& key, T& object, std::pair<char const, M T::> const& memberInfo) ^~~~~~~~ /usr/local/include/ThorSerialize/Serialize.tpp:488:23: note: inherited here using Parent::Parent; ^~ /usr/local/include/ThorSerialize/Serialize.tpp:488:23: note: no known conversion for argument 5 from ‘const std::pair<const char, Type1>’ to ‘const std::pair<const char, Type1 Type2::>&’ In file included from /usr/local/include/ThorSerialize/JsonParser.h:20:0, from /usr/local/include/ThorSerialize/JsonThor.h:14, from main.cpp:2: /usr/local/include/ThorSerialize/Serialize.h:207:7: note: candidate: constexpr ThorsAnvil::Serialize::DeSerializeMemberContainer<Type2, Type1>::DeSerializeMemberContainer(const ThorsAnvil::Serialize::DeSerializeMemberContainer<Type2, Type1>&) class DeSerializeMemberContainer ^~~~~~ In file included from /usr/local/include/ThorSerialize/Serialize.h:429:0, from /usr/local/include/ThorSerialize/JsonParser.h:20, from /usr/local/include/ThorSerialize/JsonThor.h:14, from main.cpp:2: /usr/local/include/ThorSerialize/Serialize.tpp:488:23: note: inherited here using Parent::Parent; ^~ /usr/local/include/ThorSerialize/Serialize.tpp:488:23: note: candidate expects 1 argument, 5 provided In file included from /usr/local/include/ThorSerialize/JsonParser.h:20:0, from /usr/local/include/ThorSerialize/JsonThor.h:14, from main.cpp:2: /usr/local/include/ThorSerialize/Serialize.h:207:7: note: candidate: constexpr ThorsAnvil::Serialize::DeSerializeMemberContainer<Type2, Type1>::DeSerializeMemberContainer(ThorsAnvil::Serialize::DeSerializeMemberContainer<Type2, Type1>&&) class DeSerializeMemberContainer ^~~~~~ In file included from /usr/local/include/ThorSerialize/Serialize.h:429:0, from /usr/local/include/ThorSerialize/JsonParser.h:20, from /usr/local/include/ThorSerialize/JsonThor.h:14, from main.cpp:2: /usr/local/include/ThorSerialize/Serialize.tpp:488:23: note: inherited here using Parent::Parent; ^~ /usr/local/include/ThorSerialize/Serialize.tpp:488:23: note: candidate expects 1 argument, 5 provided /usr/local/include/ThorSerialize/Serialize.tpp:484:7: note: candidate: constexpr ThorsAnvil::Serialize::DeSerializeMember<Type2, Type1, (ThorsAnvil::Serialize::TraitType)3>::DeSerializeMember(const ThorsAnvil::Serialize::DeSerializeMember<Type2, Type1, (ThorsAnvil::Serialize::TraitType)3>&) class DeSerializeMember: public TraitsInfo<T, M, Type>::DeSerializeMember ^~~~~ /usr/local/include/ThorSerialize/Serialize.tpp:484:7: note: candidate expects 1 argument, 5 provided /usr/local/include/ThorSerialize/Serialize.tpp:484:7: note: candidate: constexpr ThorsAnvil::Serialize::DeSerializeMember<Type2, Type1, (ThorsAnvil::Serialize::TraitType)3>::DeSerializeMember(ThorsAnvil::Serialize::DeSerializeMember<Type2, Type1, (ThorsAnvil::Serialize::TraitType)3>&&) /usr/local/include/ThorSerialize/Serialize.tpp:484:7: note: candidate expects 1 argument, 5 provided /usr/local/include/ThorSerialize/Serialize.tpp: In instantiation of ‘ThorsAnvil::Serialize::SerializeMember<T, M> ThorsAnvil::Serialize::make_SerializeMember(ThorsAnvil::Serialize::Serializer&, ThorsAnvil::Serialize::PrinterInterface&, const T&, const std::pair<const char, M>&) [with T = Type2; M = Type1; typename std::remove_cv::type = Type1]’: /usr/local/include/ThorSerialize/Serialize.tpp:788:45: required from ‘void ThorsAnvil::Serialize::Serializer::printEachMember(const T&, const Members&, std::index_sequence<Seq ...>&) [with T = Type2; Members = std::tuple<std::pair<const char, int>, std::pair<const char, Type1> >; long unsigned int ...Seq = {0, 1}; std::index_sequence<Seq ...> = std::integer_sequence<long unsigned int, 0, 1>]’ /usr/local/include/ThorSerialize/Serialize.tpp:795:5: required from ‘void ThorsAnvil::Serialize::Serializer::printMembers(const T&, const std::tuple<_Elements ...>&) [with T = Type2; Members = {std::pair<const char, int>, std::pair<const char, Type1>}]’ /usr/local/include/ThorSerialize/Serialize.tpp:839:5: required from ‘void ThorsAnvil::Serialize::Serializer::printObjectMembers(const T&) [with T = Type2]’ /usr/local/include/ThorSerialize/Serialize.tpp:577:13: required from ‘void ThorsAnvil::Serialize::SerializerForBlock<traitType, T>::printMembers() [with ThorsAnvil::Serialize::TraitType traitType = (ThorsAnvil::Serialize::TraitType)3; T = Type2]’ /usr/local/include/ThorSerialize/Serialize.tpp:808:5: required from ‘void ThorsAnvil::Serialize::Serializer::print(const T&) [with T = Type2]’ /usr/local/include/ThorSerialize/Exporter.h:35:17: required from ‘std::ostream& ThorsAnvil::Serialize::operator<<(std::ostream&, const ThorsAnvil::Serialize::Exporter<ThorsAnvil::Serialize::Json, Type2>&)’ main.cpp:25:34: required from here /usr/local/include/ThorSerialize/Serialize.tpp:775:12: error: no matching function for call to ‘ThorsAnvil::Serialize::SerializeMember<Type2, Type1, (ThorsAnvil::Serialize::TraitType)3>::SerializeMember(ThorsAnvil::Serialize::Serializer&, ThorsAnvil::Serialize::PrinterInterface&, const Type2&, const std::pair<const char, Type1>&)’ return SerializeMember<T,M>(ser, printer, object, memberInfo); ^~~~~~~~~~~~~~ /usr/local/include/ThorSerialize/Serialize.tpp:736:1: note: candidate: ThorsAnvil::Serialize::SerializeMemberContainer<T, M>::SerializeMemberContainer(ThorsAnvil::Serialize::Serializer&, ThorsAnvil::Serialize::PrinterInterface&, const T&, const std::pair<const char, M T::>&) [with T = Type2; M = Type1] SerializeMemberContainer<T, M>::SerializeMemberContainer(Serializer&, PrinterInterface& printer, T const& object, std::pair<char const, M T::> const& memberInfo) ^~~~~~~~~~ /usr/local/include/ThorSerialize/Serialize.tpp:769:23: note: inherited here using Parent::Parent; ^~ /usr/local/include/ThorSerialize/Serialize.tpp:769:23: note: no known conversion for argument 4 from ‘const std::pair<const char, Type1>’ to ‘const std::pair<const char, Type1 Type2::>&’ In file included from /usr/local/include/ThorSerialize/JsonParser.h:20:0, from /usr/local/include/ThorSerialize/JsonThor.h:14, from main.cpp:2: /usr/local/include/ThorSerialize/Serialize.h:254:7: note: candidate: constexpr ThorsAnvil::Serialize::SerializeMemberContainer<Type2, Type1>::SerializeMemberContainer(const ThorsAnvil::Serialize::SerializeMemberContainer<Type2, Type1>&) class SerializeMemberContainer ^~~~~~~~ In file included from /usr/local/include/ThorSerialize/Serialize.h:429:0, from /usr/local/include/ThorSerialize/JsonParser.h:20, from /usr/local/include/ThorSerialize/JsonThor.h:14, from main.cpp:2: /usr/local/include/ThorSerialize/Serialize.tpp:769:23: note: inherited here using Parent::Parent; ^~ /usr/local/include/ThorSerialize/Serialize.tpp:769:23: note: candidate expects 1 argument, 4 provided In file included from /usr/local/include/ThorSerialize/JsonParser.h:20:0, from /usr/local/include/ThorSerialize/JsonThor.h:14, from main.cpp:2: /usr/local/include/ThorSerialize/Serialize.h:254:7: note: candidate: constexpr ThorsAnvil::Serialize::SerializeMemberContainer<Type2, Type1>::SerializeMemberContainer(ThorsAnvil::Serialize::SerializeMemberContainer<Type2, Type1>&&) class SerializeMemberContainer ^~~~~~~~ In file included from /usr/local/include/ThorSerialize/Serialize.h:429:0, from /usr/local/include/ThorSerialize/JsonParser.h:20, from /usr/local/include/ThorSerialize/JsonThor.h:14, from main.cpp:2: /usr/local/include/ThorSerialize/Serialize.tpp:769:23: note: inherited here using Parent::Parent; ^~ /usr/local/include/ThorSerialize/Serialize.tpp:769:23: note: candidate expects 1 argument, 4 provided /usr/local/include/ThorSerialize/Serialize.tpp:765:7: note: candidate: constexpr ThorsAnvil::Serialize::SerializeMember<Type2, Type1, (ThorsAnvil::Serialize::TraitType)3>::SerializeMember(const ThorsAnvil::Serialize::SerializeMember<Type2, Type1, (ThorsAnvil::Serialize::TraitType)3>&) class SerializeMember: public TraitsInfo<T, M, Type>::SerializeMember ^~~~~~~ /usr/local/include/ThorSerialize/Serialize.tpp:765:7: note: candidate expects 1 argument, 4 provided /usr/local/include/ThorSerialize/Serialize.tpp:765:7: note: candidate: constexpr ThorsAnvil::Serialize::SerializeMember<Type2, Type1, (ThorsAnvil::Serialize::TraitType)3>::SerializeMember(ThorsAnvil::Serialize::SerializeMember<Type2, Type1, (ThorsAnvil::Serialize::TraitType)3>&&) /usr/local/include/ThorSerialize/Serialize.tpp:765:7: note: candidate expects 1 argument, 4 provided

Loki-Astari commented 1 year ago

Resolved in latest build: https://github.com/Loki-Astari/ThorsSerializer/blob/master/src/Serialize/test/Issue67Test.cpp