QLinkedList: fix range-erase() aliasing bug on shared instances


When calling range-erase() on a shared instance, the loop around unary
erase() would fail to properly adjust the passed iterators and, as a
consequence, alter the copy.

Given that QLinkedList iterators are supposed to be stable across
insertions and removals, and given that there's an explicit test for
unary erase() for this scenario, it follows that this ought to work
properly for range-erase(), too.

There's no function to convert _two_ iterators when detaching, so take
a cue from the detach-remove epic (QTBUG-103329) and just don't detach,
but only copy the kept elements over to a new list, and swap with that.

Add a test that fails without this fix. Can't commit it as an XFAIL
in a separate commit, as it might invoke UB.

For Qt 6, we ought to have ported QLinkedList over to a shared
std::list, like we did for QMap. Might still do that for Qt 7.

[ChangeLog][QtCore5Compat][QLinkedList] Fixed a bug in range-erase()
that would alter implicitly shared copies of the list erase() was
called on.

Pick-to: 6.11 6.10 6.8 6.5
Change-Id: I31a484bae34e1ba878e07ba9f51335c4ee2b2595
Reviewed-by: MÃ¥rten Nordheim <marten.nordheim@qt.io>
commitb5e9009c0745171f7081e0c4d9c59a139380bc95
parenta22a48bd175a639ddfafb8a325e58195a3290617
authorMarc Mutz <marc.mutz@qt.io>
committerMarc Mutz <marc.mutz@qt.io>
commit timeMon, 22 Dec 2025 11:31:01 +0100