Skip to content

Clone every item before clearing a Stack, Queue or ConcurrentQueue in DeepCloneFrom [patch] - #126

Merged
matt-edmondson merged 1 commit into
mainfrom
claude/stack-queue-clone-before-clear
Nov 4, 2026
Merged

matt-edmondson merged 1 commit into
mainfrom
claude/stack-queue-clone-before-clear

Conversation

@matt-edmondson

Copy link
Copy Markdown
Contributor

Fixes #124

What was wrong

#115 added DeepCloneFrom overloads for Stack<T>, Queue<T> and ConcurrentQueue<T>. They cleared the destination first and then cloned each item while refilling it. If an item's DeepClone threw, the destination was left holding part of the source, with its own contents gone. That is the #90 failure, brought back on these types.

What changed

  • A private CloneAll helper snapshots the source and deep clones every item, in order.
  • The three overloads call it first and touch dest only after every clone has succeeded. The ConcurrentStack<T> overload already worked this way and is unchanged.
  • DeepCloneFromExceptionSafetyTests now covers all four types. When the second item's clone throws, each test checks that the destination keeps its original contents in the original pop or dequeue order.

Tests

  • With the fix: 103/103 pass, including the existing InPlaceStackQueueTests for order and self-clone.
  • With the library change reverted: the Stack, Queue and ConcurrentQueue tests fail. The ConcurrentStack test passes either way and is there as a guard.

Generated by Claude Code

… DeepCloneFrom [patch]

The Stack<T>, Queue<T> and ConcurrentQueue<T> overloads of DeepCloneFrom
cleared the destination and cloned inside the refill loop, so an item
whose DeepClone threw left the destination holding part of the source
with its own contents gone: the #90 failure, brought back by overloads
added on a parallel branch.

They now clone every item first, through a shared CloneAll helper, and
touch the destination only once all clones have succeeded, as the
ConcurrentStack<T> overload already did. DeepCloneFromExceptionSafetyTests
covers all four types.

Fixes #124

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017vfJW5fUnJtnsd89SqCrfW
@sonarqubecloud

sonarqubecloud Bot commented Nov 4, 2026

Copy link
Copy Markdown

@matt-edmondson
matt-edmondson merged commit ea73a04 into main Nov 4, 2026
15 checks passed
@matt-edmondson
matt-edmondson deleted the claude/stack-queue-clone-before-clear branch November 4, 2026 22:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants