Skip to content

Make the library headers at least as noexcept as MSVC STL - #93

Open
jmgilbert2 wants to merge 2 commits into
masterfrom
feat/noexcept-library
Open

jmgilbert2 wants to merge 2 commits into
masterfrom
feat/noexcept-library

Conversation

@jmgilbert2

Copy link
Copy Markdown
Owner

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, __int128 and the char8_t/char16_t/char32_t specializations.
  • bitset: the base classes, reference and bitset itself. to_ulong, to_uint32 and to_uint64 are noexcept when N fits the target type. set, reset, flip and test with a position stay non-noexcept, as in std, because they throw out_of_range.
  • Iterators:
    • reverse_iterator, move_iterator and move_sentinel: all members and operators.
    • back_insert_iterator and back_inserter.
    • The range access functions (begin/end/rbegin/rend and 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/max and the literals.
  • Function objects and functional.h helpers:
    • the comparison and arithmetic function objects, including the <void> specializations;
    • hash, mem_fn, reference_wrapper::operator() and not_fn.
  • pair, tuple, array, span, string_view, uniform_int_distribution, isnan, and min/max (plus min_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.
  • The adaptors' comparisons, differences and operator* use MSVC's conditions on the base iterator's operators, and those conditions ignore EASTL's by-value base() copy. Likewise, the constructors that take an iterator use MSVC's is_nothrow_move_constructible even though EASTL copies the argument.
  • Element access that contains EASTL_ASSERT (array and span operator[]/front/back) is noexcept, like MSVC's. Only an assert handler that throws would terminate.

Testing

  • Tests are static_assert blocks in TestNumericLimits, TestChrono, TestBitset, TestIterator, TestFunctional, TestUtility, TestTuple, TestArray, TestSpan, TestStringView and TestRandom. All fail to compile on master.
  • Probes compare noexcept(expr) against MSVC STL with cl and clang-cl in C++17 and latest. Every area went to 0 mismatches.
  • All 8 configurations pass with no warning change against the master baseline: cl and clang-cl in latest Debug, latest Release and C++17 Release with exceptions off, and in latest Release with exceptions on.

🤖 Generated with Claude Code

jmgilbert2 and others added 2 commits November 10, 2026 17:16
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>
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.

1 participant