Skip to content

fixing issue 2549#2567

Merged
lemire merged 2 commits intomasterfrom
issue2549
Dec 18, 2025
Merged

fixing issue 2549#2567
lemire merged 2 commits intomasterfrom
issue2549

Conversation

@lemire
Copy link
Member

@lemire lemire commented Dec 17, 2025

Short title (summary):
Fixing issue #2549

Description
The JSON builder should have allowed custom types using C++20 tag_invoke, but the feature was broken. Sadly.

Type of change

  • Bug fix
  • New feature
  • Refactor / cleanup
  • Documentation / tests
  • Other (please describe):

@lemire
Copy link
Member Author

lemire commented Dec 17, 2025

@pgrAm Could you review/verify? Thanks for the report.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes issue #2549 where custom type serialization using C++20 tag_invoke was broken in the JSON builder. The fix removes the erroneous custom_deserializable constraint (which is for deserialization, not serialization) and properly implements forwarding references to support both lvalue and rvalue custom types.

Key changes:

  • Fixed serialize_tag::operator() to use forwarding references and remove incorrect constraint
  • Updated string_builder::append() to properly forward arguments to tag_invoke
  • Added conditional compilation support for C++26 #embed feature to prevent compilation errors when the feature is unavailable

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 5 comments.

File Description
include/simdjson/generic/ondemand/json_string_builder.h Removed incorrect custom_deserializable constraint and changed serialize_tag::operator() and append() to use forwarding references
include/simdjson/generic/ondemand/json_string_builder-inl.h Updated append() implementation to correctly call tag_invoke with forwarding
tests/builder/builder_string_builder_tests.cpp Added Car2549 struct and issue2549() test to verify custom serialization via tag_invoke works correctly
tests/compile_time/compile_time_json_tests.cpp Wrapped C++26 #embed feature usage in conditional compilation to prevent errors on compilers without support

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@pgrAm
Copy link
Contributor

pgrAm commented Dec 17, 2025

@pgrAm Could you review/verify? Thanks for the report.

Changes look about right, I'll give it a try

@pgrAm
Copy link
Contributor

pgrAm commented Dec 17, 2025

Can confirm, @lemire your branch appears to be working for me

@lemire
Copy link
Member Author

lemire commented Dec 18, 2025

@pgrAm Much appreciated.

@lemire lemire merged commit 7ad9fe6 into master Dec 18, 2025
156 checks passed
@lemire lemire deleted the issue2549 branch December 18, 2025 01:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

stringbuilder example does not compile in C++20, serialize_tag should not require custom_deserializable<T>

3 participants