Skip to content

Fix #4041: Support zero-member types in NLOHMANN_DEFINE_TYPE_* macros#5142

Open
suchetindrakanty wants to merge 1 commit intonlohmann:developfrom
suchetindrakanty:fix-issue-4041
Open

Fix #4041: Support zero-member types in NLOHMANN_DEFINE_TYPE_* macros#5142
suchetindrakanty wants to merge 1 commit intonlohmann:developfrom
suchetindrakanty:fix-issue-4041

Conversation

@suchetindrakanty
Copy link
Copy Markdown

Fixes #4041

This PR addresses an issue where NLOHMANN_DEFINE_TYPE_* macros fail when used with zero members.

Problem

When VA_ARGS is empty, macro expansion generates invalid code, causing compilation errors.

Solution

  • Wrapped macro expansions with VA_OPT to ensure code is only generated when arguments are present
  • Prevents invalid expansions for zero-member types
  • Maintains existing behavior for non-empty cases

Testing

  • Added test cases for intrusive and non-intrusive macros
  • Covered WITH_DEFAULT and ONLY_SERIALIZE variants
  • Verified empty structs serialize to {}
  • Verified deserialization works correctly

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

NLOHMANN_DEFINE_TYPE_* fails with zero members

1 participant