Skip to content

fix(util): enforce nothrow move constraint on fixed_vector element type#1874

Open
rishabhvaish wants to merge 3 commits intoEVerest:mainfrom
rishabhvaish:fix/improve-fixed-vector-nothrow-constraint
Open

fix(util): enforce nothrow move constraint on fixed_vector element type#1874
rishabhvaish wants to merge 3 commits intoEVerest:mainfrom
rishabhvaish:fix/improve-fixed-vector-nothrow-constraint

Conversation

@rishabhvaish
Copy link

Summary

  • Adds static_assert constraints requiring element types with move operations to be noexcept, as requested in Improve fixed_vector util #1814
  • Simplifies move constructor and move assignment operator to be unconditionally noexcept
  • Removes ~140 lines of throwing-move rollback logic that is no longer reachable
  • Updates tests: removes throwing-move test cases, adds compile-time static_assert verification

Closes #1814

Test plan

  • Existing fixed_vector tests pass (removed tests for now-invalid throwing-move types)
  • New NothrowMoveConstraint test verifies static_assert works for int, std::string, and custom nothrow-movable types
  • static_assert fires at compile time for types with throwing move constructors/assignment

Signed-off-by: Rishabh Vaish rishabhvaish.904@gmail.com

🤖 Generated with Claude Code

@mlitre
Copy link
Contributor

mlitre commented Feb 27, 2026

Hello @rishabhvaish thank you for your contribution! The changes look good to me. However, can you make sure to format the changes correctly and fix the unit tests? It seems like some test are now irrelevant since we have removed support for throwable move / copy assignment/ constructions

@mlitre mlitre self-assigned this Feb 27, 2026
@rishabhvaish
Copy link
Author

Thanks @mlitre for the review! I'll fix the formatting and remove/update the unit tests that are no longer relevant since the throwable move/copy support was removed. Will push an update shortly.

@mlitre
Copy link
Contributor

mlitre commented Mar 3, 2026

Hey @rishabhvaish everything is looking pretty good! I still see some structs and tests that are no longer required (eg ThrowsOnCopy, etc). We would like to completely remove those and only have a test to show that objects that throw on copy / construction are no longer allowed correctly.

rishabhvaish and others added 3 commits March 3, 2026 23:45
Add static_assert to reject types with potentially throwing move
constructors or move assignment operators. This eliminates the
throwing-move code paths that silently swallowed exceptions, leaving
callers with empty vectors and no error notification.

The previous implementation provided two move paths: a fast noexcept
path and a "strong guarantee" path for throwing moves. The latter
caught exceptions internally and did not propagate them, which meant
users had to defensively check for empty vectors after every move
operation. By requiring nothrow move operations at compile time, we:

- Prevent silent data loss from swallowed move exceptions
- Remove ~140 lines of complex rollback/recovery logic
- Make move construction and assignment unconditionally noexcept
- Align with standard library containers' best practices for
  embedded/real-time use cases

This constraint is compatible with all standard library types commonly
used with fixed_vector (int, std::string, std::unique_ptr, etc.) as
they all provide nothrow move operations.

Closes EVerest#1814

Signed-off-by: Rishabh Vaish <rishabhvaish.904@gmail.com>
- Fix clang-format alignment issue in move_assign_from template parameter
- Add explicit noexcept move constructors/assignment operators to
  ThrowsOnCopy and ThrowsOnNthCopy test types so they satisfy the new
  static_assert constraint while still testing copy-exception safety
- Change ExceptionSafety test to pass const lvalue to push_back to
  ensure copy constructor (not move) is exercised

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Signed-off-by: Rishabh Vaish <rishabhvaish.904@gmail.com>
…d tests

Remove ThrowsOnCopy, ThrowsOnDefaultConstruct, and ThrowsOnNthCopy
structs along with their associated tests (ExceptionSafety,
TryEmplaceBackExceptionDefaultConstruct, InitializerListStrongException).

These are no longer relevant since fixed_vector now enforces nothrow
move constraints via static_assert, rejecting types with throwing move
operations at compile time.

Add ThrowingMoveTypesAreRejected test that verifies via static_assert
that types with throwing move constructors/assignments fail the trait
checks that fixed_vector relies on for its compile-time rejection.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Signed-off-by: Rishabh Vaish <rishabhvaish.904@gmail.com>
@rishabhvaish rishabhvaish force-pushed the fix/improve-fixed-vector-nothrow-constraint branch from 60640f7 to f8d5115 Compare March 4, 2026 07:45
@rishabhvaish
Copy link
Author

Thanks @mlitre! Done in f8d5115 — removed ThrowsOnCopy, ThrowsOnDefaultConstruct, ThrowsOnNthCopy and their associated tests (ExceptionSafety, TryEmplaceBackExceptionDefaultConstruct, InitializerListStrongException).

Replaced them with a single ThrowingMoveTypesAreRejected test that uses static_assert to verify types with throwing move operations (ThrowingMoveConstructor, ThrowingMoveAssignment, ThrowingBothMoveOps) correctly fail the nothrow trait checks that fixed_vector's internal static_assert enforces.

@mlitre
Copy link
Contributor

mlitre commented Mar 4, 2026

@rishabhvaish looks good to me! You just to fix the linting issue and then we're good! Thank you for your contribution!

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.

Improve fixed_vector util

2 participants