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

NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE fails if the length of the argument is 10 #2280

Closed
2 of 5 tasks
mzyy94 opened this issue Jul 17, 2020 · 1 comment · Fixed by #2287
Closed
2 of 5 tasks

NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE fails if the length of the argument is 10 #2280

mzyy94 opened this issue Jul 17, 2020 · 1 comment · Fixed by #2287
Assignees
Labels
kind: bug kind: enhancement/improvement solution: duplicate the issue is a duplicate; refer to the linked issue instead solution: proposed fix a fix for the issue has been proposed and waits for confirmation
Milestone

Comments

@mzyy94
Copy link

mzyy94 commented Jul 17, 2020

What is the issue you have?

A compilation error occurred while calling NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE and NLOHMANN_DEFINE_TYPE_INTRUSIVE with 9 or 10 members.
It' caused by wrong definition of NLOHMANN_JSON_PASTE10 and NLOHMAN_JSON_PASTE11 implemented by #2225

#define NLOHMANN_JSON_PASTE10(func, v1, v2, v3, v4, v5, v6, v7, v8, v9) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE8(func, v2, v3, v4, v5, v6, v7, v8, v9)
#define NLOHMANN_JSON_PASTE11(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE8(func, v2, v3, v4, v5, v6, v7, v8, v9, v10)

Please describe the steps to reproduce the issue.

  1. Define a struct or class with 9 or 10 members.
  2. Call NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE or NLOHMANN_DEFINE_TYPE_INTRUSIVE with them like shown in this example.
  3. Compile the code.

Can you provide a small but working code example?

#include "single_include/nlohmann/json.hpp"

namespace shopping {
struct customer {
    unsigned int postcode;
    std::string address1;
    std::string address2;
    std::string city;
    std::string country;
    unsigned int telephone;

    std::string name;
    unsigned int age;
    std::string sex;
};
NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(customer, postcode, address1, address2, city, country, telephone, name, age, sex);
} // namespace shopping

int main() {}

What is the expected behavior?

Compilation fails.

test.cpp:16:113: error: too many arguments provided to function-like macro invocation
NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(customer, postcode, address1, address2, city, country, telephone, name, age, sex);
                                                                                                                ^
./single_include/nlohmann/json.hpp:2166:9: note: macro 'NLOHMANN_JSON_PASTE8' defined here
#define NLOHMANN_JSON_PASTE8(func,  v1, v2, v3, v4, v5, v6, v7)              NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE7(func, v2, v3, v4, v5, v6, v7)
        ^
test.cpp:16:1: error: use of undeclared identifier 'NLOHMANN_JSON_PASTE8'
NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(customer, postcode, address1, address2, city, country, telephone, name, age, sex);
^
./single_include/nlohmann/json.hpp:2189:75: note: expanded from macro 'NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE'
    void to_json(nlohmann::json& j, const Type& t) { NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_PASTE(NLOHMANN_JSON_TO, __VA_ARGS__)) } \
                                                                          ^
./single_include/nlohmann/json.hpp:2157:9: note: expanded from macro 'NLOHMANN_JSON_PASTE'
        NLOHMANN_JSON_PASTE10, NLOHMANN_JSON_PASTE9, NLOHMANN_JSON_PASTE8, NLOHMANN_JSON_PASTE7, \
        ^
test.cpp:16:113: error: too many arguments provided to function-like macro invocation
NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(customer, postcode, address1, address2, city, country, telephone, name, age, sex);
                                                                                                                ^
./single_include/nlohmann/json.hpp:2166:9: note: macro 'NLOHMANN_JSON_PASTE8' defined here
#define NLOHMANN_JSON_PASTE8(func,  v1, v2, v3, v4, v5, v6, v7)              NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE7(func, v2, v3, v4, v5, v6, v7)
        ^
test.cpp:16:1: error: use of undeclared identifier 'NLOHMANN_JSON_PASTE8'
NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(customer, postcode, address1, address2, city, country, telephone, name, age, sex);
^
./single_include/nlohmann/json.hpp:2190:77: note: expanded from macro 'NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE'
    void from_json(const nlohmann::json& j, Type& t) { NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_PASTE(NLOHMANN_JSON_FROM, __VA_ARGS__)) }
                                                                            ^
./single_include/nlohmann/json.hpp:2157:9: note: expanded from macro 'NLOHMANN_JSON_PASTE'
        NLOHMANN_JSON_PASTE10, NLOHMANN_JSON_PASTE9, NLOHMANN_JSON_PASTE8, NLOHMANN_JSON_PASTE7, \
        ^
4 errors generated.

And what is the actual behavior instead?

The compilation is successful.

Which compiler and operating system are you using?

  • Compiler: Apple clang version 11.0.3 (clang-1103.0.32.62)
  • Operating system: macOS Catalina 10.15.5(19F101)

Which version of the library did you use?

  • latest release version 3.7.3
  • other release - please state the version: ___
  • the develop branch

If you experience a compilation error: can you compile and run the unit tests?

  • yes
  • no - please copy/paste the error message below
@nlohmann
Copy link
Owner

Duplicate of #2267.

@nlohmann nlohmann added the solution: duplicate the issue is a duplicate; refer to the linked issue instead label Jul 17, 2020
@nlohmann nlohmann added kind: enhancement/improvement solution: proposed fix a fix for the issue has been proposed and waits for confirmation labels Jul 20, 2020
@nlohmann nlohmann self-assigned this Jul 20, 2020
@nlohmann nlohmann added this to the Release 3.8.1 milestone Jul 20, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind: bug kind: enhancement/improvement solution: duplicate the issue is a duplicate; refer to the linked issue instead solution: proposed fix a fix for the issue has been proposed and waits for confirmation
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants