fix: support zero-member types in NLOHMANN_DEFINE_TYPE_* macros#5177
fix: support zero-member types in NLOHMANN_DEFINE_TYPE_* macros#5177leno23 wants to merge 1 commit into
Conversation
Add NLOHMANN_JSON_PASTE0 and NLOHMANN_JSON_DOUBLE_PASTE0 so empty member lists expand to no-op serialization code. Fixes nlohmann#4041.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: ca10ccfbc9
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| NLOHMANN_JSON_PASTE1, \ | ||
| NLOHMANN_JSON_PASTE0)(__VA_ARGS__)) | ||
| #define NLOHMANN_JSON_PASTE0(func) |
There was a problem hiding this comment.
Route empty member lists to the zero-arg paste branch
Adding NLOHMANN_JSON_PASTE0 here does not make zero-member NLOHMANN_DEFINE_TYPE_* calls work, because the call sites pass NLOHMANN_JSON_PASTE(NLOHMANN_JSON_TO, __VA_ARGS__); when __VA_ARGS__ is empty this still leaves an empty argument after the comma, so dispatch selects NLOHMANN_JSON_PASTE2 and expands to invalid code like nlohmann_json_t.. In practice, NLOHMANN_DEFINE_TYPE_INTRUSIVE(MyType) still fails to compile, so the new tests introduced in this commit cannot build.
Useful? React with 👍 / 👎.
🔴 Amalgamation check failed! 🔴The source code has not been amalgamated. @leno23 |
|
@leno23 Can you explain your patch? It seems it is just generated by Cursor, but never even tried to be compiled. |
|
AI slop. |
Summary
NLOHMANN_DEFINE_TYPE_*with no member fields produced invalidto_json/from_jsonbodies (e.g.nlohmann_json_j[] = nlohmann_json_t.).Adds
NLOHMANN_JSON_PASTE0andNLOHMANN_JSON_DOUBLE_PASTE0so empty__VA_ARGS__expand to no-ops, matching the expected empty function bodies.Fixes #4041.
Test plan
unit-udt_macro.cpp.Made with Cursor