Skip to content

Commit 2bcced8

Browse files
committed
Verify forward_list self-merging is a no-op
1 parent 27e686c commit 2bcced8

File tree

5 files changed

+33
-2
lines changed

5 files changed

+33
-2
lines changed

libcxx/docs/Status/Cxx23Issues.csv

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@
137137
"`LWG3593 <https://wg21.link/LWG3593>`__","Several iterators' ``base() const &`` and ``lazy_split_view::outer-iterator::value_type::end()`` missing ``noexcept``","2021-10 (Virtual)","","",""
138138
"`LWG3595 <https://wg21.link/LWG3595>`__","Exposition-only classes proxy and postfix-proxy for ``common_iterator`` should be fully ``constexpr``","2021-10 (Virtual)","|Complete|","14",""
139139
"","","","","",""
140-
"`LWG3088 <https://wg21.link/LWG3088>`__","``forward_list::merge`` behaviour unclear when passed ``*this``","2022-02 (Virtual)","","",""
140+
"`LWG3088 <https://wg21.link/LWG3088>`__","``forward_list::merge`` behaviour unclear when passed ``*this``","2022-02 (Virtual)","|Complete|","21",""
141141
"`LWG3471 <https://wg21.link/LWG3471>`__","``polymorphic_allocator::allocate`` does not satisfy ``Cpp17Allocator`` requirements","2022-02 (Virtual)","","",""
142142
"`LWG3525 <https://wg21.link/LWG3525>`__","``uses_allocator_construction_args`` fails to handle types convertible to ``pair``","2022-02 (Virtual)","","",""
143143
"`LWG3598 <https://wg21.link/LWG3598>`__","``system_category().default_error_condition(0)`` is underspecified","2022-02 (Virtual)","","",""

libcxx/test/std/containers/sequences/forwardlist/forwardlist.ops/merge_lvalue.pass.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
// <forward_list>
1010

1111
// void merge(forward_list& x);
12+
// If (addressof(x) == this) does nothing; otherwise ...
1213

1314
#include <forward_list>
1415
#include <iterator>
@@ -109,5 +110,12 @@ int main(int, char**) {
109110
}
110111
#endif
111112

113+
{ // Make sure self-merging does nothing.
114+
int a[] = {1, 2, 3, 4, 5};
115+
std::forward_list<int> c(a, a + sizeof(a) / sizeof(a[0]));
116+
c.merge(c);
117+
assert((c == std::forward_list<int>(a, a + sizeof(a) / sizeof(a[0]))));
118+
}
119+
112120
return 0;
113121
}

libcxx/test/std/containers/sequences/forwardlist/forwardlist.ops/merge_lvalue_pred.pass.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
// <forward_list>
1010

1111
// template <class Compare> void merge(forward_list& x, Compare comp);
12+
// If (addressof(x) == this) does nothing; otherwise ...
1213

1314
#include <forward_list>
1415
#include <iterator>
@@ -91,7 +92,6 @@ int main(int, char**) {
9192
C c3(std::begin(t3), std::end(t3));
9293
assert(c1 == c3);
9394
}
94-
9595
#if TEST_STD_VER >= 11
9696
{ // Test with a different allocator.
9797
typedef int T;
@@ -110,5 +110,12 @@ int main(int, char**) {
110110
}
111111
#endif
112112

113+
{ // Make sure self-merging does nothing.
114+
int a[] = {5, 4, 3, 2, 1};
115+
std::forward_list<int> c(a, a + sizeof(a) / sizeof(a[0]));
116+
c.merge(c, std::greater<int>());
117+
assert((c == std::forward_list<int>(a, a + sizeof(a) / sizeof(a[0]))));
118+
}
119+
113120
return 0;
114121
}

libcxx/test/std/containers/sequences/forwardlist/forwardlist.ops/merge_rvalue.pass.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
// <forward_list>
1212

1313
// void merge(forward_list&& x);
14+
// If (addressof(x) == this) does nothing; otherwise ...
1415

1516
#include <forward_list>
1617
#include <functional>
@@ -102,5 +103,12 @@ int main(int, char**) {
102103
assert(c1 == c3);
103104
}
104105

106+
{ // Make sure self-merging does nothing.
107+
int a[] = {1, 2, 3, 4, 5};
108+
std::forward_list<int> c(a, a + sizeof(a) / sizeof(a[0]));
109+
c.merge(std::move(c));
110+
assert((c == std::forward_list<int>(a, a + sizeof(a) / sizeof(a[0]))));
111+
}
112+
105113
return 0;
106114
}

libcxx/test/std/containers/sequences/forwardlist/forwardlist.ops/merge_rvalue_pred.pass.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
// <forward_list>
1212

1313
// template <class Compare> void merge(forward_list&& x, Compare comp);
14+
// If (addressof(x) == this) does nothing; otherwise ...
1415

1516
#include <forward_list>
1617
#include <functional>
@@ -103,5 +104,12 @@ int main(int, char**) {
103104
assert(c1 == c3);
104105
}
105106

107+
{ // Make sure self-merging does nothing.
108+
int a[] = {5, 4, 3, 2, 1};
109+
std::forward_list<int> c(a, a + sizeof(a) / sizeof(a[0]));
110+
c.merge(std::move(c), std::greater<int>());
111+
assert((c == std::forward_list<int>(a, a + sizeof(a) / sizeof(a[0]))));
112+
}
113+
106114
return 0;
107115
}

0 commit comments

Comments
 (0)