Repository navigation
Allow tag_invoke to throw without std::terminate (#2858) - #2872
Merged
Merged
Conversation
A user tag_invoke customization is allowed to throw, but the exception
could never reach the caller: every simdjson_result<...>::get<T>()
wrapper was unconditionally noexcept, so a throw hit std::terminate.
- New concept nothrow_gettable<T, ValT>: true when there is no custom
tag_invoke for T or that tag_invoke is noexcept. get<T>() and
get<T>(T&) on value, array, object, document, document_reference and
all their simdjson_result<...> wrappers are noexcept(nothrow_gettable).
Built-in types and noexcept customizations keep every layer noexcept.
document_reference::get was checking the document customization; fixed.
- Allocating customizations (containers, maps, unique_ptr, shared_ptr,
reflected structs) are noexcept(false) so bad_alloc and user
exceptions propagate, and so that the exception specification of
get<T>() never recurses into T for self-referential types.
- The appendable-container loop always deserializes into a temporary and
moves it in: master's "in place" path already went through a
simdjson_result<T> temporary, a plain temporary is ~3% faster on the
citm static-reflection benchmark, and it needs no cleanup on error or
exception (the container keeps exactly the successfully parsed
elements).
- unique_ptr/shared_ptr customizations own the allocation before calling
get(), so a throw cannot leak and the caller's pointer is unchanged.
- Static reflection: exceptions propagate out of reflected structs too.
The reflected-struct tag_invoke also matched simdjson's own types
(array, object, number, document, ...), conflicting with their
explicit noexcept get<T>() specializations; they are excluded now.
With reflection enabled get<T>() is noexcept(false) for every struct
T, so a legacy explicit specialization
template<> simdjson_result<Car> value::get() noexcept { ... }
no longer matches the primary template; such specializations are
redundant under reflection and the two tests carrying them guard them
with !SIMDJSON_STATIC_REFLECTION. Documented in basics.md.
- New tests/ondemand/ondemand_tag_invoke_exception_tests.cpp.
1 of 6 tasks
lemire
added a commit
that referenced
this pull request
Sep 22, 2026
…-Wmaybe-uninitialized GCC 11.4 (Ubuntu 22.04 CI, Debug/-Og developer build with -Werror) reports a false-positive 'v may be used uninitialized' on the json_sequence subtest since #2870 landed on top of #2872. The variable is only read after get(v) returned SUCCESS, so this is purely a diagnostic issue; the warning flips on unrelated call-graph changes in headers pulled in via simdjson.h. Initialize all the int64_t v locals in the file so the other identical sites cannot start failing the same way later.
lemire
added a commit
that referenced
this pull request
Sep 22, 2026
…-Wmaybe-uninitialized (#2875) GCC 11.4 (Ubuntu 22.04 CI, Debug/-Og developer build with -Werror) reports a false-positive 'v may be used uninitialized' on the json_sequence subtest since #2870 landed on top of #2872. The variable is only read after get(v) returned SUCCESS, so this is purely a diagnostic issue; the warning flips on unrelated call-graph changes in headers pulled in via simdjson.h. Initialize all the int64_t v locals in the file so the other identical sites cannot start failing the same way later.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
A user tag_invoke customization is allowed to throw, but the exception could never reach the caller: every simdjson_result<...>::get() wrapper was unconditionally noexcept, so a throw hit std::terminate.
Fixes #2858 reported by @maxbachmann