Skip to content

Commit b350bc2

Browse files
authored
[libc++] Verify forward_list self-merging is a no-op (#129985)
https://wg21.link/LWG3088 requires that `forward_list::merge()` is a no-op when passed `*this`, which aligns with the behavior of `list::merge`. Although libc++'s implementation of `forward_list::merge()` already meets this requirement, there were no tests to verify this behavior. This patch adds the necessary tests to ensure that self-merging remains a no-op and prevents any future regressions on this. Closes #104942.
1 parent 9a078a3 commit b350bc2

File tree

5 files changed

+29
-1
lines changed

5 files changed

+29
-1
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|","Yes",""
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: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,5 +109,12 @@ int main(int, char**) {
109109
}
110110
#endif
111111

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

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,5 +110,12 @@ int main(int, char**) {
110110
}
111111
#endif
112112

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

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,5 +102,12 @@ int main(int, char**) {
102102
assert(c1 == c3);
103103
}
104104

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

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,5 +103,12 @@ int main(int, char**) {
103103
assert(c1 == c3);
104104
}
105105

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

0 commit comments

Comments
 (0)