You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 3752006
Browse filesBrowse the repository at this point in the historyBrowse files
Allow tag_invoke to throw without std::terminate (#2858) (#2872)
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.
0 commit comments