Skip to content

fix: Don't mark Any copy operations noexcept#5495

Merged
kodiakhq[bot] merged 5 commits into
mainfrom
claude/any-copy-noexcept
May 23, 2026
Merged

fix: Don't mark Any copy operations noexcept#5495
kodiakhq[bot] merged 5 commits into
mainfrom
claude/any-copy-noexcept

Conversation

@paulgessinger

@paulgessinger paulgessinger commented May 22, 2026

Copy link
Copy Markdown
Member

Let's try not making the copy operations in Any noexcept. They mask actual paths that can throw (the contained object's constructor). For vector optimization, I think the moves being noexcept should be sufficient.

This also fixes an exception bug that was masked by noexcept before, where an exception on copy would produce an Any pointing at invalid memory.

@github-actions github-actions Bot added this to the next milestone May 22, 2026
@github-actions github-actions Bot added the Component - Core Affects the Core module label May 22, 2026
@github-actions

github-actions Bot commented May 22, 2026

Copy link
Copy Markdown
Contributor

📊: Physics performance monitoring for c325844

Full contents

physmon summary

@paulgessinger paulgessinger force-pushed the claude/any-copy-noexcept branch from 860f7d9 to 7dfcd6c Compare May 22, 2026 15:14
Comment thread Core/include/Acts/Utilities/Any.hpp
@paulgessinger paulgessinger marked this pull request as ready for review May 22, 2026 15:16
claude added 4 commits May 22, 2026 18:16
The value constructor, copy constructor and copy assignment were marked
noexcept(kAnyNoexcept) (i.e. noexcept in normal builds), but for types
larger than the small buffer they allocate on the heap and run the stored
type's copy/constructor. A std::bad_alloc or a throwing copy therefore
called std::terminate. std::any has the same shape and deliberately leaves
its copy operations potentially-throwing; only moves (a pointer steal for
heap values) are noexcept.

Remove noexcept from the value constructor, copy constructor and copy
assignment so these exceptions propagate. Keep the move constructor and
move assignment noexcept so std::vector<Any> still moves rather than
copies on reallocation.

Relaxing the copy-assignment noexcept exposes a pre-existing
exception-safety hole: when the new value's copy throws, the target was
left with its handler set but no value, so destruction would operate on
uninitialized storage (assert/zombie). Reset the handler to empty on
throw so a failed copy assignment leaves the target empty.

Add a regression test and static_asserts pinning the exception
specifications.

https://claude.ai/code/session_013by5hPDzWJCe9gjXNDZjLs
AnyTests.cpp is compiled into two targets: the normal build and an
AnyDebug build that defines _ACTS_ANY_ENABLE_TRACK_ALLOCATIONS (which
sets kAnyNoexcept = false so the tracking hooks may throw). The new
static_asserts assumed the move operations are always noexcept, which is
only true in the normal build, so they failed to compile the AnyDebug
target. Tie the move assertions to detail::kAnyNoexcept.

Also wrap the AnyCopyExceptionPropagates body in an inner scope so the
held value is destroyed before CHECK_ANY_ALLOCATIONS(), matching the
other test cases (otherwise its still-live allocation trips the leak
check in the tracking build).

https://claude.ai/code/session_013by5hPDzWJCe9gjXNDZjLs
clang-tidy's readability-named-parameter flagged the unnamed parameter in
HeapCopyThrows's throwing copy constructor. Add a /*unused*/ comment to
match the project convention, and apply clang-format (wraps the long
static_assert line).

https://claude.ai/code/session_013by5hPDzWJCe9gjXNDZjLs
Add an explicit !std::is_base_of_v<AnyBaseAll, std::decay_t<T>> guard to
the forwarding-reference constructor. This was already enforced indirectly
(isStorable returns false for AnyBaseAll-derived types), but stating it at
the constructor makes the exclusion of recursive/self construction
explicit and robust against future changes to isStorable.

https://claude.ai/code/session_013by5hPDzWJCe9gjXNDZjLs
@paulgessinger paulgessinger force-pushed the claude/any-copy-noexcept branch from 7dfcd6c to c669468 Compare May 22, 2026 15:16
@sonarqubecloud

Copy link
Copy Markdown

@kodiakhq kodiakhq Bot merged commit d4ffb31 into main May 23, 2026
74 checks passed
@andiwand andiwand modified the milestones: next, v46.7.0 May 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Component - Core Affects the Core module

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants