From 1e1fd1efd0107e1a530d828528449fddb1eb743d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vojt=C4=9Bch=20Michal?= Date: Mon, 1 Dec 2025 18:39:54 +0100 Subject: [PATCH] flat_multiset::emplace_hint() shall not calculate upper_bound but rather search for closest position. --- stl/inc/flat_set | 13 +++++++------ tests/libcxx/expected_results.txt | 6 ------ 2 files changed, 7 insertions(+), 12 deletions(-) diff --git a/stl/inc/flat_set b/stl/inc/flat_set index fe26264da45..086bdcd7abd 100644 --- a/stl/inc/flat_set +++ b/stl/inc/flat_set @@ -577,21 +577,22 @@ private: } else { _STL_INTERNAL_STATIC_ASSERT(is_same_v, _Kty>); - // look for upper_bound(_Val) + // look for closest position just prior to _Where, respecting ordering if (_Where == _End || _Compare(_Val, *_Where)) { // _Val < *_Where if (_Where == _Begin || !_Compare(_Val, *(_Where - 1))) { - // _Val >= *(_Where-1) ~ upper_bound is _Where + // _Val >= *(_Where-1) ~ closest valid position is _Where } else { - // _Val < *(_Where-1) ~ upper_bound is in [_Begin,_Where-1] + // _Val < *(_Where-1) ~ closest valid position is upper_bound(_Val) located in [_Begin,_Where-1] _Where = _STD upper_bound(_Begin, _Where - 1, _Val, _Pass_comp()); } + // _Val < *_Where, so upper_bound is indeed "as close as possible" + _STL_INTERNAL_CHECK(_Can_insert(_Where, _Val)); } else { - // _Val >= *_Where ~ upper_bound is in [_Where+1,_End] - _Where = _STD upper_bound(_Where + 1, _End, _Val, _Pass_comp()); + // _Val >= *_Where ~ search for lower_bound in [_Where,_End] to place _Val "as close as possible" + _Where = _STD lower_bound(_Where, _End, _Val, _Pass_comp()); } - _STL_INTERNAL_CHECK(_Can_insert(_Where, _Val)); return _Mycont.emplace(_Where, _STD forward<_Ty>(_Val)); } } diff --git a/tests/libcxx/expected_results.txt b/tests/libcxx/expected_results.txt index adfd72a9139..caf425bcd34 100644 --- a/tests/libcxx/expected_results.txt +++ b/tests/libcxx/expected_results.txt @@ -346,12 +346,6 @@ std/containers/container.adaptors/flat.set/flat.set.cons/move.pass.cpp FAIL std/containers/container.adaptors/flat.multiset/flat.multiset.cons/move_assign.pass.cpp FAIL std/containers/container.adaptors/flat.set/flat.set.cons/move_assign.pass.cpp FAIL -# FIXME! Assertion failed: r == m.begin() + 2 -std/containers/container.adaptors/flat.multiset/flat.multiset.modifiers/emplace_hint.pass.cpp FAIL - -# FIXME! Assertion failed: r == m.begin() + 1 -std/containers/container.adaptors/flat.multiset/flat.multiset.modifiers/insert_iter_rv.pass.cpp FAIL - # FIXME! warning C4242: 'initializing': conversion from 'int' to '_Ty', possible loss of data std/containers/container.adaptors/flat.multiset/flat.multiset.cons/sorted_iter_iter.pass.cpp:0 FAIL std/containers/container.adaptors/flat.multiset/flat.multiset.cons/sorted_iter_iter.pass.cpp:1 FAIL