-
-
Notifications
You must be signed in to change notification settings - Fork 7.1k
Open
Description
Description
I found it annoying when working with multiple tiny polymorphic classes, trying to provide identical interface for each of them, that I can't use the macro for a class that has no members to (de)serialize.
Reproduction steps
Use (probably) any of the NLOHMANN_DEFINE_TYPE_*
macros with only first argument and no members.
F.e. NLOHMANN_DEFINE_TYPE_INTRUSIVE(MyClass)
Expected vs. actual results
Expected:
friend void to_json(nlohmann::json&, const MyClass&) {}
friend void from_json(const nlohmann::json&, MyClass&) {}
Actual:
friend void to_json(nlohmann::json& nlohmann_json_j, const MyClass& nlohmann_json_t) {
nlohmann_json_j[] = nlohmann_json_t.;
}
friend void from_json(const nlohmann::json& nlohmann_json_j, MyClass& nlohmann_json_t) {
nlohmann_json_j.at().get_to(nlohmann_json_t.);
}
Minimal code example
class MyClass
{
NLOHMANN_DEFINE_TYPE_INTRUSIVE(MyClass);
};
Error messages
Error C2661 'nlohmann::json_abi_v3_11_2::basic_json<std::map,std::vector,std::string,bool,int64_t,uint64_t,double,std::allocator,nlohmann::json_abi_v3_11_2::adl_serializer,std::vector<uint8_t,std::allocator<uint8_t>>>::at': no overloaded function takes 0 arguments
Error C2661 'nlohmann::json_abi_v3_11_2::basic_json<std::map,std::vector,std::string,bool,int64_t,uint64_t,double,std::allocator,nlohmann::json_abi_v3_11_2::adl_serializer,std::vector<uint8_t,std::allocator<uint8_t>>>::at': no overloaded function takes 0 arguments
Error C2661 'nlohmann::json_abi_v3_11_2::basic_json<std::map,std::vector,std::string,bool,int64_t,uint64_t,double,std::allocator,nlohmann::json_abi_v3_11_2::adl_serializer,std::vector<uint8_t,std::allocator<uint8_t>>>::at': no overloaded function takes 0 arguments
Error C2661 'nlohmann::json_abi_v3_11_2::basic_json<std::map,std::vector,std::string,bool,int64_t,uint64_t,double,std::allocator,nlohmann::json_abi_v3_11_2::adl_serializer,std::vector<uint8_t,std::allocator<uint8_t>>>::at': no overloaded function takes 0 arguments
Error C2059 syntax error: ')'
Error C2059 syntax error: ')'
Error C2059 syntax error: ')'
Error C2059 syntax error: ')'
Error C2059 syntax error: ']'
Error C2059 syntax error: ']'
Error C2059 syntax error: ']'
Error C2059 syntax error: ']'
Compiler and operating system
Microsoft Visual C++ 2022
Library version
3.11.2
Validation
- The bug also occurs if the latest version from the
develop
branch is used. - I can successfully compile and run the unit tests.