diff options
author | Marshall Clow <mclow.lists@gmail.com> | 2017-08-28 23:16:13 +0000 |
---|---|---|
committer | Marshall Clow <mclow.lists@gmail.com> | 2017-08-28 23:16:13 +0000 |
commit | a763b36ff4f3179a3b3d18bf446f075df5188c68 (patch) | |
tree | 81e983a70cce94b53b31e0eb6102c9910511d51d /libcxx/test/std/algorithms/alg.sorting | |
parent | 4cae10856132f3f038f4f7361c847214e2149f42 (diff) | |
download | bcm5719-llvm-a763b36ff4f3179a3b3d18bf446f075df5188c68.tar.gz bcm5719-llvm-a763b36ff4f3179a3b3d18bf446f075df5188c68.zip |
Fix PR31166: std::inplace_merge seems to be unstable. Thanks to Jan Wilken Dörrie for the suggested fix.
llvm-svn: 311952
Diffstat (limited to 'libcxx/test/std/algorithms/alg.sorting')
-rw-r--r-- | libcxx/test/std/algorithms/alg.sorting/alg.merge/inplace_merge_comp.pass.cpp | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/libcxx/test/std/algorithms/alg.sorting/alg.merge/inplace_merge_comp.pass.cpp b/libcxx/test/std/algorithms/alg.sorting/alg.merge/inplace_merge_comp.pass.cpp index 369bccf9c83..6fd8fd4f924 100644 --- a/libcxx/test/std/algorithms/alg.sorting/alg.merge/inplace_merge_comp.pass.cpp +++ b/libcxx/test/std/algorithms/alg.sorting/alg.merge/inplace_merge_comp.pass.cpp @@ -116,6 +116,25 @@ test() test<Iter>(1000); } +struct less_by_first { + template <typename Pair> + bool operator()(const Pair& lhs, const Pair& rhs) { + return std::less<typename Pair::first_type>()(lhs.first, rhs.first); + } +}; + +void test_PR31166 () +{ + typedef std::pair<int, int> P; + typedef std::vector<P> V; + const V vec {{1, 0}, {2, 0}, {2, 1}, {2, 2}, {2, 3}}; + for ( int i = 0; i < 5; ++i ) { + V res = vec; + std::inplace_merge(res.begin(), res.begin() + i, res.end(), less_by_first()); + assert(res == vec); + } +} + int main() { test<bidirectional_iterator<int*> >(); @@ -146,4 +165,6 @@ int main() delete [] ia; } #endif // TEST_STD_VER >= 11 + + test_PR31166(); } |