Repository navigation
Make the library headers at least as noexcept as MSVC STL - #93
Open
jmgilbert2 wants to merge 2 commits into
Open
jmgilbert2 wants to merge 2 commits into
jmgilbert2 wants to merge 2 commits into
Conversation
Exception specifications of numeric_limits, chrono, bitset, the iterator adaptors (reverse_iterator, move_iterator, move_sentinel, insert iterators) and the range access functions, the function objects, mem_fn, reference_wrapper, not_fn, pair, tuple, array, span, string_view, uniform_int_distribution, isnan and min/max now match or exceed MSVC STL 14.51 in C++17 and latest. Conditional specs copy MSVC's conditions with EASTL traits. - numeric_limits: every member is noexcept, as the standard requires. - move_iterator::base() is unconditionally noexcept (MSVC returns a const reference in C++20; EASTL returns a copy). The adaptors' comparisons and differences use MSVC's conditions on the base iterator's operators. - bitset::to_ulong and the to_uint32/to_uint64 conversions are noexcept when N fits the target type. - Functions with assertions (array/span element access) are noexcept like MSVC's. Only exception specifications change; no code generation changes. Tests are static_asserts that fail on the previous headers. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
EASTL may be more noexcept than std. These functions get noexcept although MSVC doesn't mark them, because EASTL's implementation can't throw with exceptions disabled or enabled (no allocation, no user-provided operation, no throw path): - use_self/use_first/use_second, GetPair::get, TupleLeaf::getInternal, getImpl and swallow (reference access only). - internal::floating_point_hash (bit_cast). - front_insert_iterator's constructor, operator* and operator++, front_inserter, and insert_iterator's operator* and operator++ (the same operations MSVC marks for back_insert_iterator). - array<T, 0>::fill, span's SpanStorage constructors, and span's container constructors conditionally on eastl::data and eastl::size. - bitset's BitsetCountBits, GetFirstBit, GetLastBit, from_uint32 and from_uint64 (word-level bit operations). - the byte-pointer lexicographical_compare overloads (memcmp) and Internal::urng_mul128. Functions that call user-provided operations or have a throw path with exceptions enabled are unchanged. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
Part A1 of the noexcept pass: EASTL's library headers become at least as noexcept as MSVC STL 14.51, in C++17 and latest. Only exception specifications change, so generated code doesn't. A last commit in this pass will add noexcept beyond MSVC where EASTL's implementation can't throw in either exception mode.
Changed
About 626 unconditional and 230 conditional spec insertions. These counts include the matching out-of-line definitions.
numeric_limits: every member is now noexcept, as the standard requires. This covers all specializations, including the compiler-specific float variants,__int128and thechar8_t/char16_t/char32_tspecializations.bitset: the base classes,referenceandbitsetitself.to_ulong,to_uint32andto_uint64are noexcept when N fits the target type.set,reset,flipandtestwith a position stay non-noexcept, as in std, because they throwout_of_range.reverse_iterator,move_iteratorandmove_sentinel: all members and operators.back_insert_iteratorandback_inserter.begin/end/rbegin/rendand their const forms,size/ssize/empty/data), using MSVC's conditions.chrono:duration,time_point, their operators and the casts, conditional on an arithmetic representation as in MSVC;zero/min/maxand the literals.functional.hhelpers:<void>specializations;hash,mem_fn,reference_wrapper::operator()andnot_fn.pair,tuple,array,span,string_view,uniform_int_distribution,isnan, andmin/max(plusmin_alt/max_alt).Decisions to review
move_iterator::base()is unconditionally noexcept. In C++20, MSVC returns a const reference here; EASTL returns a copy. With exceptions on, an iterator whose copy throws would terminate.operator*use MSVC's conditions on the base iterator's operators, and those conditions ignore EASTL's by-valuebase()copy. Likewise, the constructors that take an iterator use MSVC'sis_nothrow_move_constructibleeven though EASTL copies the argument.EASTL_ASSERT(arrayandspanoperator[]/front/back) is noexcept, like MSVC's. Only an assert handler that throws would terminate.Testing
static_assertblocks in TestNumericLimits, TestChrono, TestBitset, TestIterator, TestFunctional, TestUtility, TestTuple, TestArray, TestSpan, TestStringView and TestRandom. All fail to compile on master.noexcept(expr)against MSVC STL with cl and clang-cl in C++17 and latest. Every area went to 0 mismatches.🤖 Generated with Claude Code