Fix bug in the void etl::unlink(first, last) for bidirectional links. (#1149)

* Reproduce bug in the `void etl::unlink(first, last)` for bidirectional links.

- correct `test_unlink_range_bidirectional_link` unit test according to the documentation - now this test fails.
- enhance `test_intrusive_list::test_splice_range_self` unit test to verify also `etl_previous` links after splicing lists - now unit test crashes.

* Fix bug in the `void etl::unlink(first, last)` for bidirectional links.

- `test_unlink_range_bidirectional_link` unit test now is green.
- `test_intrusive_list::test_splice_range_self` is not crashing anymore and green.
This commit is contained in:
Sergei 2025-07-14 10:50:28 +03:00 committed by GitHub
parent 400f438958
commit 4979c8a20b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 9 additions and 5 deletions

View File

@ -882,7 +882,6 @@ namespace etl
if (first.etl_previous != ETL_NULLPTR)
{
first.etl_previous->etl_next = last.etl_next;
last.clear();
}
first.etl_previous = ETL_NULLPTR;

View File

@ -1225,15 +1225,14 @@ namespace
etl::link<BLink1>(data1, data0);
etl::link<BLink1>(data0, nullptr);
// According to the documentation, `data1`/`data2` remain linked to each other.
etl::unlink<BLink0>(data1, data2);
data1.BLink0::clear();
data2.BLink0::clear();
CHECK(data0.BLink0::etl_previous == nullptr);
CHECK(data0.BLink0::etl_next == &data3);
CHECK(data1.BLink0::etl_previous == nullptr);
CHECK(data1.BLink0::etl_next == nullptr);
CHECK(data2.BLink0::etl_previous == nullptr);
CHECK(data1.BLink0::etl_next == &data2);
CHECK(data2.BLink0::etl_previous == &data1);
CHECK(data2.BLink0::etl_next == nullptr);
CHECK(data3.BLink0::etl_previous == &data0);
CHECK(data3.BLink0::etl_next == nullptr);

View File

@ -1420,6 +1420,12 @@ namespace
CHECK(are_equal);
CHECK_EQUAL(data0.size(), compare0.size());
// Double check that after splicing `etl_previous` is also correct - `.reverse()` easy way to do so.
data0.reverse();
compare0.reverse();
are_equal = std::equal(data0.begin(), data0.end(), compare0.begin());
CHECK(are_equal);
}
//*************************************************************************