Skip to content

Make the vocabulary types at least as noexcept as MSVC STL - #92

Open
jmgilbert2 wants to merge 1 commit into
masterfrom
feat/noexcept-vocabulary
Open

jmgilbert2 wants to merge 1 commit into
masterfrom
feat/noexcept-vocabulary

Conversation

@jmgilbert2

Copy link
Copy Markdown
Owner

Part A3 of the noexcept pass: EASTL's vocabulary types become at least as noexcept as MSVC STL 14.51, in C++17 and latest. Exception specifications are the only change, so no generated code changes.

Changed (about 48 unconditional and 89 conditional specs)

  • optional and expected/unexpected: constructors, assignments, emplace, comparisons, value_or/error_or, make_optional.
  • function and fixed_function: move construction and move assignment are now noexcept, keeping the current small-buffer storage rule (the decided option (a)). The in-place move helper was already noexcept.
  • unique_ptr::operator* (conditional) and operator[].
  • weak_ptr::reset/swap and weak_from_this.
  • construct_at, destroy_at, align.
  • eastl::allocator and dummy_allocator constructors, assignment, deallocate, get_name/set_name, ==/!=. This also makes containers' default constructors noexcept, through their existing conditional specs.
  • hash<monostate> and hash<variant>. hash<variant> uses a small variant_is_nothrow_hashable trait, like MSVC's _Is_nothrow_hashable.

Decisions to review

  • variant(in_place_index_t, initializer_list, args...) is now unconditionally noexcept. MSVC's spec there is noexcept(is_constructible_v<...>) (<variant> line 990), which is always true under its constraint; the sibling constructors use is_nothrow_constructible_v. With exceptions on, a throwing element constructor terminates, as it does on MSVC. Reverting to the correct condition is a one-line change.
  • expected::value_or/error_or use is_nothrow_copy/move_constructible && is_nothrow_constructible<T, U> instead of is_nothrow_convertible. The result is the same for these convertible types. EASTL's is_nothrow_convertible emits C4244 on narrowing conversions, which is a separate trait issue.

Still pending

  • variant's comparison operators and hash<variant<int, ...>> reach MSVC's answer once the function-object part of this pass (A1) lands. Their specs here are already correct.

Testing

  • Tests are static_assert blocks in TestOptional, TestExpected, TestSmartPtr, TestFixedFunction, TestFunctional, TestMemory, TestAllocator and TestVariant. All of them fail to compile on master.
  • Probes compared noexcept(expr) against MSVC STL with cl and clang-cl in C++17 and latest. Every mismatch went to 0, apart from the variant items listed under "Still pending".
  • 8 configurations (cl and clang-cl; latest Debug, latest Release and C++17 Release with exceptions off; latest Release with exceptions on): all pass, with no warning change against the master baseline.

🤖 Generated with Claude Code

Exception specifications of optional, expected/unexpected, unique_ptr,
weak_ptr/enable_shared_from_this, function/fixed_function, variant's hash,
construct_at/destroy_at/align and eastl::allocator/dummy_allocator now match or
exceed MSVC STL 14.51 in C++17 and latest. Conditional specs copy MSVC's
conditions with EASTL traits (variant's hash uses a small
variant_is_nothrow_hashable trait, like MSVC's _Is_nothrow_hashable).

- function and fixed_function: move construction and move assignment are
  noexcept with the current small-buffer storage rule (the in-place move helper
  was already noexcept), as decided for this pass.
- variant(in_place_index_t, initializer_list, args...) is unconditionally
  noexcept: MSVC's spec there is is_constructible_v, which is always true under
  its constraint.
- expected::value_or/error_or use is_nothrow_copy/move_constructible &&
  is_nothrow_constructible instead of is_nothrow_convertible, which gives the
  same result for these convertible types without EASTL's is_nothrow_convertible
  C4244 narrowing warning.

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>
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