Skip to content

Commit 714e28e

Browse files
committed
[libc++] Fix insert() calling incorrect constructors
1 parent ec752c6 commit 714e28e

File tree

10 files changed

+70
-135
lines changed

10 files changed

+70
-135
lines changed

libcxx/include/__hash_table

Lines changed: 2 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -852,15 +852,6 @@ public:
852852
template <class... _Args>
853853
_LIBCPP_HIDE_FROM_ABI iterator __emplace_hint_multi(const_iterator __p, _Args&&... __args);
854854

855-
_LIBCPP_HIDE_FROM_ABI pair<iterator, bool> __insert_unique(__container_value_type&& __x) {
856-
return __emplace_unique_key_args(_NodeTypes::__get_key(__x), std::move(__x));
857-
}
858-
859-
template <class _Pp, __enable_if_t<!is_same<__remove_cvref_t<_Pp>, __container_value_type>::value, int> = 0>
860-
_LIBCPP_HIDE_FROM_ABI pair<iterator, bool> __insert_unique(_Pp&& __x) {
861-
return __emplace_unique(std::forward<_Pp>(__x));
862-
}
863-
864855
template <class _ValueT = _Tp, __enable_if_t<__is_hash_value_type<_ValueT>::value, int> = 0>
865856
_LIBCPP_HIDE_FROM_ABI void __insert_unique_from_orphaned_node(value_type&& __value) {
866857
using __key_type = typename _NodeTypes::key_type;
@@ -877,16 +868,6 @@ public:
877868
__h.release();
878869
}
879870

880-
template <class _Pp>
881-
_LIBCPP_HIDE_FROM_ABI iterator __insert_multi(_Pp&& __x) {
882-
return __emplace_multi(std::forward<_Pp>(__x));
883-
}
884-
885-
template <class _Pp>
886-
_LIBCPP_HIDE_FROM_ABI iterator __insert_multi(const_iterator __p, _Pp&& __x) {
887-
return __emplace_hint_multi(__p, std::forward<_Pp>(__x));
888-
}
889-
890871
template <class _ValueT = _Tp, __enable_if_t<__is_hash_value_type<_ValueT>::value, int> = 0>
891872
_LIBCPP_HIDE_FROM_ABI void __insert_multi_from_orphaned_node(value_type&& __value) {
892873
using __key_type = typename _NodeTypes::key_type;
@@ -903,10 +884,6 @@ public:
903884
__h.release();
904885
}
905886

906-
_LIBCPP_HIDE_FROM_ABI pair<iterator, bool> __insert_unique(const __container_value_type& __x) {
907-
return __emplace_unique_key_args(_NodeTypes::__get_key(__x), __x);
908-
}
909-
910887
#if _LIBCPP_STD_VER >= 17
911888
template <class _NodeHandle, class _InsertReturnType>
912889
_LIBCPP_HIDE_FROM_ABI _InsertReturnType __node_handle_insert_unique(_NodeHandle&& __nh);
@@ -1336,7 +1313,7 @@ void __hash_table<_Tp, _Hash, _Equal, _Alloc>::__assign_unique(_InputIterator __
13361313
__deallocate_node(__cache);
13371314
}
13381315
for (; __first != __last; ++__first)
1339-
__insert_unique(*__first);
1316+
__emplace_unique(*__first);
13401317
}
13411318

13421319
template <class _Tp, class _Hash, class _Equal, class _Alloc>
@@ -1368,7 +1345,7 @@ void __hash_table<_Tp, _Hash, _Equal, _Alloc>::__assign_multi(_InputIterator __f
13681345
__deallocate_node(__cache);
13691346
}
13701347
for (; __first != __last; ++__first)
1371-
__insert_multi(_NodeTypes::__get_value(*__first));
1348+
__emplace_multi(_NodeTypes::__get_value(*__first));
13721349
}
13731350

13741351
template <class _Tp, class _Hash, class _Equal, class _Alloc>

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/ext/hash_map

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -520,7 +520,7 @@ public:
520520
_LIBCPP_HIDE_FROM_ABI const_iterator end() const { return __table_.end(); }
521521

522522
_LIBCPP_HIDE_FROM_ABI std::pair<iterator, bool> insert(const value_type& __x) {
523-
return __table_.__insert_unique(__x);
523+
return __table_.__emplace_unique(__x);
524524
}
525525
_LIBCPP_HIDE_FROM_ABI iterator insert(const_iterator, const value_type& __x) { return insert(__x).first; }
526526
template <class _InputIterator>
@@ -625,7 +625,7 @@ template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
625625
template <class _InputIterator>
626626
inline void hash_map<_Key, _Tp, _Hash, _Pred, _Alloc>::insert(_InputIterator __first, _InputIterator __last) {
627627
for (; __first != __last; ++__first)
628-
__table_.__insert_unique(*__first);
628+
__table_.__emplace_unique(*__first);
629629
}
630630

631631
template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
@@ -744,7 +744,7 @@ public:
744744
_LIBCPP_HIDE_FROM_ABI const_iterator begin() const { return __table_.begin(); }
745745
_LIBCPP_HIDE_FROM_ABI const_iterator end() const { return __table_.end(); }
746746

747-
_LIBCPP_HIDE_FROM_ABI iterator insert(const value_type& __x) { return __table_.__insert_multi(__x); }
747+
_LIBCPP_HIDE_FROM_ABI iterator insert(const value_type& __x) { return __table_.__emplace_unique(__x); }
748748
_LIBCPP_HIDE_FROM_ABI iterator insert(const_iterator, const value_type& __x) { return insert(__x); }
749749
template <class _InputIterator>
750750
_LIBCPP_HIDE_FROM_ABI void insert(_InputIterator __first, _InputIterator __last);
@@ -831,7 +831,7 @@ template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
831831
template <class _InputIterator>
832832
inline void hash_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::insert(_InputIterator __first, _InputIterator __last) {
833833
for (; __first != __last; ++__first)
834-
__table_.__insert_multi(*__first);
834+
__table_.__emplace_unique(*__first);
835835
}
836836

837837
template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>

libcxx/include/ext/hash_set

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,7 @@ public:
279279
_LIBCPP_HIDE_FROM_ABI const_iterator end() const { return __table_.end(); }
280280

281281
_LIBCPP_HIDE_FROM_ABI std::pair<iterator, bool> insert(const value_type& __x) {
282-
return __table_.__insert_unique(__x);
282+
return __table_.__emplace_unique(__x);
283283
}
284284
_LIBCPP_HIDE_FROM_ABI iterator insert(const_iterator, const value_type& __x) { return insert(__x).first; }
285285
template <class _InputIterator>
@@ -365,7 +365,7 @@ template <class _Value, class _Hash, class _Pred, class _Alloc>
365365
template <class _InputIterator>
366366
inline void hash_set<_Value, _Hash, _Pred, _Alloc>::insert(_InputIterator __first, _InputIterator __last) {
367367
for (; __first != __last; ++__first)
368-
__table_.__insert_unique(*__first);
368+
__table_.__emplace_unique(*__first);
369369
}
370370

371371
template <class _Value, class _Hash, class _Pred, class _Alloc>
@@ -458,7 +458,7 @@ public:
458458
_LIBCPP_HIDE_FROM_ABI const_iterator begin() const { return __table_.begin(); }
459459
_LIBCPP_HIDE_FROM_ABI const_iterator end() const { return __table_.end(); }
460460

461-
_LIBCPP_HIDE_FROM_ABI iterator insert(const value_type& __x) { return __table_.__insert_multi(__x); }
461+
_LIBCPP_HIDE_FROM_ABI iterator insert(const value_type& __x) { return __table_.__emplace_unique(__x); }
462462
_LIBCPP_HIDE_FROM_ABI iterator insert(const_iterator, const value_type& __x) { return insert(__x); }
463463
template <class _InputIterator>
464464
_LIBCPP_HIDE_FROM_ABI void insert(_InputIterator __first, _InputIterator __last);
@@ -543,7 +543,7 @@ template <class _Value, class _Hash, class _Pred, class _Alloc>
543543
template <class _InputIterator>
544544
inline void hash_multiset<_Value, _Hash, _Pred, _Alloc>::insert(_InputIterator __first, _InputIterator __last) {
545545
for (; __first != __last; ++__first)
546-
__table_.__insert_multi(*__first);
546+
__table_.__emplace_unique(*__first);
547547
}
548548

549549
template <class _Value, class _Hash, class _Pred, class _Alloc>

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()); }

0 commit comments

Comments
 (0)