Repository navigation
futurecpp: avoid overlapping ranges in zip_iterator mutation tests - #658
Merged
4og merged 2 commits intoOct 7, 2026
Merged
Conversation
4og
requested review from
antonkri,
arkjedrz,
fbaeuerle and
pawelrutkaq
as code owners
October 5, 2026 09:51
4og
marked this pull request as draft
October 5, 2026 09:56
Contributor
|
Documentation preview for this pull request is available at: |
4og
force-pushed
the
fix/zip-iterator-test-overlapping-swap
branch
from
October 5, 2026 10:09
6119804 to
664b43a
Compare
Ehrja
reviewed
Oct 6, 2026
Ehrja
left a comment
Contributor
There was a problem hiding this comment.
The change looks fine to me. To my knowledge there is no known usecase for using the same container in overlapping manner within zip-iterator within BMW scope.
From the analysis it really originates in unspecified execution-order and thus relies on underlying "system-libraries".
I just wonder whether it is possible to "emit" the semantics of "this quirk" to users in a better way than just encoded in existing unit-tests. So maybe a doxy-note or something in public-api 🤔
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
4og
force-pushed
the
fix/zip-iterator-test-overlapping-swap
branch
from
October 6, 2026 10:41
664b43a to
b720a2e
Compare
4og
marked this pull request as ready for review
October 6, 2026 10:43
Ehrja
approved these changes
Oct 6, 2026
fbaeuerle
approved these changes
Oct 7, 2026
This branch was previously deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Two tests in
zip_iterator_test.cppfail on QNX x86_64 but pass on Linux x86_64 and QNX aarch64:container_test_basics.swap(all three container types)container_test_bi_directional.use_in_stl_algorithm_with_bidirectional_iterator_requirement(both bidirectional container types)Both tests zipped two offset views of the same container
{a, b, c} = {1.2, 3.4, 5.6}.The two zipped positions therefore referred to
(a, b)and(b, c), sharing the storage ofb.Both tests then swapped dereferenced zip iterators,
swap(*iter1, *iter2)directly andstd::reverseviaiter_swap.Root cause
zip_iterator::operator*returns azipped_tuple_likeholding references to the underlying elements.Its ADL
swapdelegates tostd::swapon the underlyingstd::tuple, which swaps the tuple elements pairwise:swap(a, b)andswap(b, c).Since both modify
b, the result depends on the order of these two swaps:(a, b, c)afterwardsswap(a, b), thenswap(b, c)(3.4, 5.6, 1.2)swap(b, c), thenswap(a, b)(5.6, 1.2, 3.4)libstdc++ swaps tuple elements left to right.
libc++ (used by QNX) implements
tuple::swapasstd::__swallow(__tuple_leaf<I, T>::swap(...)...), i.e. the element swaps are function arguments whose evaluation order is unspecified in C++17.The QNX GCC aarch64 build evaluates them left to right, the x86_64 build right to left, which yields
5.6instead of the expected3.4.More fundamentally,
(a, b)and(b, c)cannot be exchanged as independent records: after a true exchange,bwould have to hold both the originalaand the originalc.The tests relied on unspecified behavior rather than on a property of
zip_iterator.Fix
The two mutating tests now zip two independent containers (
{1.2, 3.4}and{5.6, 7.8}), so every zipped position refers to distinct storage and the swap result is independent of element swap order.Coverage is kept or improved:
swapstill checks both swapping iterator objects and swapping the dereferenced zipped values, and now asserts both positions after each step.std::reverseand now asserts both positions afterwards.The
zip_iteratorimplementation is unchanged.Read-only tests (
find,post_increment,copy_assignment, etc.) keep using offset views of a single container, since overlap is harmless there.Alternatives considered
zipped_tuple_like'sswap. This would make results identical across platforms, but the outcome for overlapping ranges would still not be a meaningful exchange. It would change library behavior only to satisfy an invalid test assumption.