Skip to content

sum: preserve iterator validity when moving sum terms - #732

Merged
evaleev merged 2 commits into
masterfrom
ajay/sum-move-erase
Oct 26, 2026
Merged

evaleev merged 2 commits into
masterfrom
ajay/sum-move-erase

Conversation

@ajay-mk

@ajay-mk ajay-mk commented Oct 24, 2026 •

Copy link
Copy Markdown
Member

The move-only Sum constructor advanced the iterator after erasing a summand. This could skip the next term or increment the end iterator, and leave the recorded constant position inconsistent with the terms.

Use the iterator returned by erase, and advance the iterator and position only when retaining a summand.

Regression tests cover merging a final constant (a segmentation fault without the fix), constants and zeros interleaved with variables (an assertion failure without the fix; the test also checks the retained order and, through a later append, the recorded constant position), and adjacent and trailing zeros (a zero is retained without the fix).

The move-only Sum constructor advanced the iterator after erasing a
summand. This could skip the next term or increment the end iterator,
and leave the recorded constant position inconsistent with the terms.

Use the iterator returned by erase, and advance the iterator and position
only when retaining a summand. Add regression tests for merging a final
constant and for constants and zeros interleaved with variables.
@ajay-mk ajay-mk added this to the 26.2 milestone Oct 24, 2026
@ajay-mk ajay-mk added the bug Something isn't working label Oct 24, 2026
@ajay-mk

ajay-mk commented Oct 24, 2026

Copy link
Copy Markdown
Member Author

Formatting check failure should be resolved after #733

… tests

The interleaved-constants section located the merged constant with find_if
and checked only its value, so neither the retained order nor the recorded
constant position was verified; with asserts disabled the old loop would
have passed it. Check the size and order directly, and verify the recorded
position through a later append, which folds into the constant only if the
position is right.

Add a section with adjacent and trailing zeros: the old loop skipped the
summand after an erased one, so the second of two adjacent zeros survived.
@evaleev
evaleev merged commit a11ba66 into master Oct 26, 2026
19 of 20 checks passed
@evaleev
evaleev deleted the ajay/sum-move-erase branch October 26, 2026 14:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants