CXX-2745 add immortal.hh and type_traits.hh #1402
Open
+129
−0
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.
Related to CXX-2745. Precursor changes to CXX-3232.
Adds two new internal bsoncxx components which are used by upcoming v1 interfaces.
The
bsoncxx::immortal<T>
class is used to define error category objects in a manner that avoids generating exit-time destructors (hence, "immortal") as can be diagnosed by the-Wexit-time-destructors
Clang warning.The pattern will look as follows:
Several new type traits are introduce to ensure consistency and correctness of v1 interfaces via static assertions. These type traits are derived from patterns observed in v_noabi interfaces and are enforced by v1 interfaces in a more rigorous manner.
The new type traits are:
is_semitrivial<T>
:T
is trivial to copy, move, and destroy ("like anint
").is_semiregular<T>
andis_regular<T>
:T
has value semantics ("like anint
orstd::string
") and is (optionally) equality-comparable.is_semitrivial<T>
impliesis_semiregular<T>
.is_nothrow_moveable<T>
:T
does not throw on destruction, move construction, or move assignment ("like astd::unique_ptr<T>
").is_nothrow_relocatable<T>
in C++26 without misleadingly implying actual nothrow relocatability (which is complicated to accurately specify). This type trait is primarily to catch missingnoexcept
specifiers and highlight immovable types.is_semitrivial<T>
impliesis_nothrow_moveable<T>
.All class types in bsoncxx and mongocxx are expected to (eventually) satisfy semiregular and nothrow moveable at a minimum to ensure consistent user-friendly behavior (e.g.
bsoncxx::document::value
is notably not semiregular). Some types may additionally support semitrivialty. Some types may additionally support regularity (equality comparison). If there are any circumstances where nothrow moveability is deliberately violated (potentially-throwing move operations or immovability), we should expect such instances to be highlighted with a negated static assertion ("we do something unusual here!") such as formongocxx::v_noabi::instance
(an immovable class type).Important
Move constructors and move assignment operators which may allocate memory are still declared
noexcept
.std::bad_alloc
exceptions are NOT accounted for by nothrow moveability, as we do not support recovering from out-of-memory situations in either the C++ or C Driver libraries.