Skip to content

Commit 5b68b3b

Browse files
committed
[libc++] Fix insert() calling incorrect constructors
1 parent 5ea29f7 commit 5b68b3b

File tree

5 files changed

+34
-76
lines changed

5 files changed

+34
-76
lines changed

libcxx/include/__tree

Lines changed: 2 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1015,32 +1015,6 @@ public:
10151015
return __emplace_hint_unique_key_args(__p, __x.first, std::forward<_Pp>(__x)).first;
10161016
}
10171017

1018-
_LIBCPP_HIDE_FROM_ABI pair<iterator, bool> __insert_unique(const value_type& __v) {
1019-
return __emplace_unique_key_args(__v, __v);
1020-
}
1021-
1022-
_LIBCPP_HIDE_FROM_ABI iterator __insert_unique(const_iterator __p, const value_type& __v) {
1023-
return __emplace_hint_unique_key_args(__p, __v, __v).first;
1024-
}
1025-
1026-
_LIBCPP_HIDE_FROM_ABI pair<iterator, bool> __insert_unique(value_type&& __v) {
1027-
return __emplace_unique_key_args(__v, std::move(__v));
1028-
}
1029-
1030-
_LIBCPP_HIDE_FROM_ABI iterator __insert_unique(const_iterator __p, value_type&& __v) {
1031-
return __emplace_hint_unique_key_args(__p, __v, std::move(__v)).first;
1032-
}
1033-
1034-
template <class _Vp, __enable_if_t<!is_same<__remove_const_ref_t<_Vp>, value_type>::value, int> = 0>
1035-
_LIBCPP_HIDE_FROM_ABI pair<iterator, bool> __insert_unique(_Vp&& __v) {
1036-
return __emplace_unique(std::forward<_Vp>(__v));
1037-
}
1038-
1039-
template <class _Vp, __enable_if_t<!is_same<__remove_const_ref_t<_Vp>, value_type>::value, int> = 0>
1040-
_LIBCPP_HIDE_FROM_ABI iterator __insert_unique(const_iterator __p, _Vp&& __v) {
1041-
return __emplace_hint_unique(__p, std::forward<_Vp>(__v));
1042-
}
1043-
10441018
template <class _ValueT = _Tp, __enable_if_t<__is_tree_value_type<_ValueT>::value, int> = 0>
10451019
_LIBCPP_HIDE_FROM_ABI void
10461020
__insert_unique_from_orphaned_node(const_iterator __p, __get_node_value_type_t<_Tp>&& __value) {
@@ -1052,22 +1026,6 @@ public:
10521026
__emplace_hint_unique(__p, std::move(__value));
10531027
}
10541028

1055-
_LIBCPP_HIDE_FROM_ABI iterator __insert_multi(value_type&& __v) { return __emplace_multi(std::move(__v)); }
1056-
1057-
_LIBCPP_HIDE_FROM_ABI iterator __insert_multi(const_iterator __p, value_type&& __v) {
1058-
return __emplace_hint_multi(__p, std::move(__v));
1059-
}
1060-
1061-
template <class _Vp>
1062-
_LIBCPP_HIDE_FROM_ABI iterator __insert_multi(_Vp&& __v) {
1063-
return __emplace_multi(std::forward<_Vp>(__v));
1064-
}
1065-
1066-
template <class _Vp>
1067-
_LIBCPP_HIDE_FROM_ABI iterator __insert_multi(const_iterator __p, _Vp&& __v) {
1068-
return __emplace_hint_multi(__p, std::forward<_Vp>(__v));
1069-
}
1070-
10711029
template <class _ValueT = _Tp, __enable_if_t<__is_tree_value_type<_ValueT>::value, int> = 0>
10721030
_LIBCPP_HIDE_FROM_ABI void __insert_multi_from_orphaned_node(const_iterator __p, value_type&& __value) {
10731031
__emplace_hint_multi(__p, const_cast<key_type&&>(__value.first), std::move(__value.second));
@@ -1360,7 +1318,7 @@ void __tree<_Tp, _Compare, _Allocator>::__assign_unique(_ForwardIterator __first
13601318
}
13611319
}
13621320
for (; __first != __last; ++__first)
1363-
__insert_unique(*__first);
1321+
__emplace_unique(*__first);
13641322
}
13651323

13661324
template <class _Tp, class _Compare, class _Allocator>
@@ -1380,7 +1338,7 @@ void __tree<_Tp, _Compare, _Allocator>::__assign_multi(_InputIterator __first, _
13801338
}
13811339
const_iterator __e = end();
13821340
for (; __first != __last; ++__first)
1383-
__insert_multi(__e, *__first);
1341+
__emplace_hint_multi(__e, *__first);
13841342
}
13851343

13861344
template <class _Tp, class _Compare, class _Allocator>

libcxx/include/map

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1073,29 +1073,29 @@ public:
10731073

10741074
template <class _Pp, __enable_if_t<is_constructible<value_type, _Pp>::value, int> = 0>
10751075
_LIBCPP_HIDE_FROM_ABI pair<iterator, bool> insert(_Pp&& __p) {
1076-
return __tree_.__insert_unique(std::forward<_Pp>(__p));
1076+
return __tree_.__emplace_unique(std::forward<_Pp>(__p));
10771077
}
10781078

10791079
template <class _Pp, __enable_if_t<is_constructible<value_type, _Pp>::value, int> = 0>
10801080
_LIBCPP_HIDE_FROM_ABI iterator insert(const_iterator __pos, _Pp&& __p) {
1081-
return __tree_.__insert_unique(__pos.__i_, std::forward<_Pp>(__p));
1081+
return __tree_.__emplace_hint_unique(__pos.__i_, std::forward<_Pp>(__p));
10821082
}
10831083

10841084
# endif // _LIBCPP_CXX03_LANG
10851085

1086-
_LIBCPP_HIDE_FROM_ABI pair<iterator, bool> insert(const value_type& __v) { return __tree_.__insert_unique(__v); }
1086+
_LIBCPP_HIDE_FROM_ABI pair<iterator, bool> insert(const value_type& __v) { return __tree_.__emplace_unique(__v); }
10871087

10881088
_LIBCPP_HIDE_FROM_ABI iterator insert(const_iterator __p, const value_type& __v) {
1089-
return __tree_.__insert_unique(__p.__i_, __v);
1089+
return __tree_.__emplace_hint_unique(__p.__i_, __v);
10901090
}
10911091

10921092
# ifndef _LIBCPP_CXX03_LANG
10931093
_LIBCPP_HIDE_FROM_ABI pair<iterator, bool> insert(value_type&& __v) {
1094-
return __tree_.__insert_unique(std::move(__v));
1094+
return __tree_.__emplace_unique(std::move(__v));
10951095
}
10961096

10971097
_LIBCPP_HIDE_FROM_ABI iterator insert(const_iterator __p, value_type&& __v) {
1098-
return __tree_.__insert_unique(__p.__i_, std::move(__v));
1098+
return __tree_.__emplace_hint_unique(__p.__i_, std::move(__v));
10991099
}
11001100

11011101
_LIBCPP_HIDE_FROM_ABI void insert(initializer_list<value_type> __il) { insert(__il.begin(), __il.end()); }
@@ -1756,42 +1756,42 @@ public:
17561756

17571757
template <class _Pp, __enable_if_t<is_constructible<value_type, _Pp>::value, int> = 0>
17581758
_LIBCPP_HIDE_FROM_ABI iterator insert(_Pp&& __p) {
1759-
return __tree_.__insert_multi(std::forward<_Pp>(__p));
1759+
return __tree_.__emplace_multi(std::forward<_Pp>(__p));
17601760
}
17611761

17621762
template <class _Pp, __enable_if_t<is_constructible<value_type, _Pp>::value, int> = 0>
17631763
_LIBCPP_HIDE_FROM_ABI iterator insert(const_iterator __pos, _Pp&& __p) {
1764-
return __tree_.__insert_multi(__pos.__i_, std::forward<_Pp>(__p));
1764+
return __tree_.__emplace_hint_multi(__pos.__i_, std::forward<_Pp>(__p));
17651765
}
17661766

1767-
_LIBCPP_HIDE_FROM_ABI iterator insert(value_type&& __v) { return __tree_.__insert_multi(std::move(__v)); }
1767+
_LIBCPP_HIDE_FROM_ABI iterator insert(value_type&& __v) { return __tree_.__emplace_multi(std::move(__v)); }
17681768

17691769
_LIBCPP_HIDE_FROM_ABI iterator insert(const_iterator __p, value_type&& __v) {
1770-
return __tree_.__insert_multi(__p.__i_, std::move(__v));
1770+
return __tree_.__emplace_hint_multi(__p.__i_, std::move(__v));
17711771
}
17721772

17731773
_LIBCPP_HIDE_FROM_ABI void insert(initializer_list<value_type> __il) { insert(__il.begin(), __il.end()); }
17741774

17751775
# endif // _LIBCPP_CXX03_LANG
17761776

1777-
_LIBCPP_HIDE_FROM_ABI iterator insert(const value_type& __v) { return __tree_.__insert_multi(__v); }
1777+
_LIBCPP_HIDE_FROM_ABI iterator insert(const value_type& __v) { return __tree_.__emplace_multi(__v); }
17781778

17791779
_LIBCPP_HIDE_FROM_ABI iterator insert(const_iterator __p, const value_type& __v) {
1780-
return __tree_.__insert_multi(__p.__i_, __v);
1780+
return __tree_.__emplace_hint_multi(__p.__i_, __v);
17811781
}
17821782

17831783
template <class _InputIterator>
17841784
_LIBCPP_HIDE_FROM_ABI void insert(_InputIterator __f, _InputIterator __l) {
17851785
for (const_iterator __e = cend(); __f != __l; ++__f)
1786-
__tree_.__insert_multi(__e.__i_, *__f);
1786+
__tree_.__emplace_hint_multi(__e.__i_, *__f);
17871787
}
17881788

17891789
# if _LIBCPP_STD_VER >= 23
17901790
template <_ContainerCompatibleRange<value_type> _Range>
17911791
_LIBCPP_HIDE_FROM_ABI void insert_range(_Range&& __range) {
17921792
const_iterator __end = cend();
17931793
for (auto&& __element : __range) {
1794-
__tree_.__insert_multi(__end.__i_, std::forward<decltype(__element)>(__element));
1794+
__tree_.__emplace_hint_multi(__end.__i_, std::forward<decltype(__element)>(__element));
17951795
}
17961796
}
17971797
# endif

libcxx/include/set

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -740,34 +740,34 @@ public:
740740
}
741741
# endif // _LIBCPP_CXX03_LANG
742742

743-
_LIBCPP_HIDE_FROM_ABI pair<iterator, bool> insert(const value_type& __v) { return __tree_.__insert_unique(__v); }
743+
_LIBCPP_HIDE_FROM_ABI pair<iterator, bool> insert(const value_type& __v) { return __tree_.__emplace_unique(__v); }
744744
_LIBCPP_HIDE_FROM_ABI iterator insert(const_iterator __p, const value_type& __v) {
745-
return __tree_.__insert_unique(__p, __v);
745+
return __tree_.__emplace_hint_unique(__p, __v);
746746
}
747747

748748
template <class _InputIterator>
749749
_LIBCPP_HIDE_FROM_ABI void insert(_InputIterator __f, _InputIterator __l) {
750750
for (const_iterator __e = cend(); __f != __l; ++__f)
751-
__tree_.__insert_unique(__e, *__f);
751+
__tree_.__emplace_hint_unique(__e, *__f);
752752
}
753753

754754
# if _LIBCPP_STD_VER >= 23
755755
template <_ContainerCompatibleRange<value_type> _Range>
756756
_LIBCPP_HIDE_FROM_ABI void insert_range(_Range&& __range) {
757757
const_iterator __end = cend();
758758
for (auto&& __element : __range) {
759-
__tree_.__insert_unique(__end, std::forward<decltype(__element)>(__element));
759+
__tree_.__emplace_hint_unique(__end, std::forward<decltype(__element)>(__element));
760760
}
761761
}
762762
# endif
763763

764764
# ifndef _LIBCPP_CXX03_LANG
765765
_LIBCPP_HIDE_FROM_ABI pair<iterator, bool> insert(value_type&& __v) {
766-
return __tree_.__insert_unique(std::move(__v));
766+
return __tree_.__emplace_unique(std::move(__v));
767767
}
768768

769769
_LIBCPP_HIDE_FROM_ABI iterator insert(const_iterator __p, value_type&& __v) {
770-
return __tree_.__insert_unique(__p, std::move(__v));
770+
return __tree_.__emplace_hint_unique(__p, std::move(__v));
771771
}
772772

773773
_LIBCPP_HIDE_FROM_ABI void insert(initializer_list<value_type> __il) { insert(__il.begin(), __il.end()); }
@@ -1209,32 +1209,32 @@ public:
12091209
}
12101210
# endif // _LIBCPP_CXX03_LANG
12111211

1212-
_LIBCPP_HIDE_FROM_ABI iterator insert(const value_type& __v) { return __tree_.__insert_multi(__v); }
1212+
_LIBCPP_HIDE_FROM_ABI iterator insert(const value_type& __v) { return __tree_.__emplace_multi(__v); }
12131213
_LIBCPP_HIDE_FROM_ABI iterator insert(const_iterator __p, const value_type& __v) {
1214-
return __tree_.__insert_multi(__p, __v);
1214+
return __tree_.__emplace_hint_multi(__p, __v);
12151215
}
12161216

12171217
template <class _InputIterator>
12181218
_LIBCPP_HIDE_FROM_ABI void insert(_InputIterator __f, _InputIterator __l) {
12191219
for (const_iterator __e = cend(); __f != __l; ++__f)
1220-
__tree_.__insert_multi(__e, *__f);
1220+
__tree_.__emplace_hint_multi(__e, *__f);
12211221
}
12221222

12231223
# if _LIBCPP_STD_VER >= 23
12241224
template <_ContainerCompatibleRange<value_type> _Range>
12251225
_LIBCPP_HIDE_FROM_ABI void insert_range(_Range&& __range) {
12261226
const_iterator __end = cend();
12271227
for (auto&& __element : __range) {
1228-
__tree_.__insert_multi(__end, std::forward<decltype(__element)>(__element));
1228+
__tree_.__emplace_hint_multi(__end, std::forward<decltype(__element)>(__element));
12291229
}
12301230
}
12311231
# endif
12321232

12331233
# ifndef _LIBCPP_CXX03_LANG
1234-
_LIBCPP_HIDE_FROM_ABI iterator insert(value_type&& __v) { return __tree_.__insert_multi(std::move(__v)); }
1234+
_LIBCPP_HIDE_FROM_ABI iterator insert(value_type&& __v) { return __tree_.__emplace_multi(std::move(__v)); }
12351235

12361236
_LIBCPP_HIDE_FROM_ABI iterator insert(const_iterator __p, value_type&& __v) {
1237-
return __tree_.__insert_multi(__p, std::move(__v));
1237+
return __tree_.__emplace_hint_multi(__p, std::move(__v));
12381238
}
12391239

12401240
_LIBCPP_HIDE_FROM_ABI void insert(initializer_list<value_type> __il) { insert(__il.begin(), __il.end()); }

libcxx/test/std/containers/map_allocator_requirement_test_templates.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ void testMapInsert() {
5050
// Testing C::insert(value_type&)
5151
Container c;
5252
ValueTp v(42, 1);
53-
cc->expect<const ValueTp&>();
53+
cc->expect<ValueTp&>();
5454
assert(c.insert(v).second);
5555
assert(!cc->unchecked());
5656
{
@@ -76,7 +76,7 @@ void testMapInsert() {
7676
// Testing C::insert(const value_type&&)
7777
Container c;
7878
const ValueTp v(42, 1);
79-
cc->expect<const ValueTp&>();
79+
cc->expect<const ValueTp&&>();
8080
assert(c.insert(std::move(v)).second);
8181
assert(!cc->unchecked());
8282
{
@@ -139,7 +139,7 @@ void testMapInsert() {
139139
// Testing C::insert(Iter, Iter) for *Iter = value_type&
140140
Container c;
141141
ValueTp ValueList[] = {ValueTp(1, 1), ValueTp(2, 1), ValueTp(3, 1)};
142-
cc->expect<ValueTp const&>(3);
142+
cc->expect<ValueTp&>(3);
143143
c.insert(std::begin(ValueList), std::end(ValueList));
144144
assert(!cc->unchecked());
145145
{
@@ -180,7 +180,7 @@ void testMapInsertHint() {
180180
// Testing C::insert(p, value_type&)
181181
Container c;
182182
ValueTp v(42, 1);
183-
cc->expect<ValueTp const&>();
183+
cc->expect<ValueTp&>();
184184
It ret = c.insert(c.end(), v);
185185
assert(ret != c.end());
186186
assert(c.size() == 1);
@@ -229,7 +229,7 @@ void testMapInsertHint() {
229229
// Testing C::insert(p, const value_type&&)
230230
Container c;
231231
const ValueTp v(42, 1);
232-
cc->expect<const ValueTp&>();
232+
cc->expect<const ValueTp&&>();
233233
It ret = c.insert(c.end(), std::move(v));
234234
assert(ret != c.end());
235235
assert(c.size() == 1);

libcxx/test/std/containers/set_allocator_requirement_test_templates.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ void testSetInsert() {
125125
// Testing C::insert(Iter, Iter) for *Iter = value_type&"
126126
Container c;
127127
ValueTp ValueList[] = {ValueTp(1), ValueTp(2), ValueTp(3)};
128-
cc->expect<ValueTp const&>(3);
128+
cc->expect<ValueTp&>(3);
129129
c.insert(std::begin(ValueList), std::end(ValueList));
130130
assert(!cc->unchecked());
131131
{

0 commit comments

Comments
 (0)