backport: re PR libstdc++/82522 (std::map::insert(value_type &&) not selected)

2017-12-28  François Dumont  <fdumont@gcc.gnu.org>

	Backport from mainline
	2017-12-20  François Dumont  <fdumont@gcc.gnu.org>

	PR libstdc++/82522
	* include/debug/map.h (map::insert(value_type&&))
	(map::insert(const_iterator, value_type&&)): Add overload for rvalues.
	* include/debug/multimap.h (multimap::insert(value_type&&))
	(multimap::insert(const_iterator, value_type&&)): Likewise.
	* include/debug/unordered_map (unordered_map::insert(value_type&&))
	(unordered_map::insert(const_iterator, value_type&&))
	(unordered_multimap::insert(value_type&&))
	(unordered_multimap::insert(const_iterator, value_type&&)): Likewise.
	* testsuite/23_containers/map/modifiers/insert/dr2354.cc (test02): New.
	* testsuite/23_containers/multimap/modifiers/insert/dr2354.cc (test02):
	New.
	* testsuite/23_containers/unordered_map/insert/dr2354.cc (test02): New.
	* testsuite/23_containers/unordered_multimap/insert/dr2354.cc (test02):
	New.

From-SVN: r256018
This commit is contained in:
François Dumont 2017-12-28 05:37:54 +00:00
parent cb6d05cd81
commit cf4a3f0859
8 changed files with 135 additions and 7 deletions

View File

@ -1,3 +1,24 @@
2017-12-28 François Dumont <fdumont@gcc.gnu.org>
Backport from mainline
2017-12-20 François Dumont <fdumont@gcc.gnu.org>
PR libstdc++/82522
* include/debug/map.h (map::insert(value_type&&))
(map::insert(const_iterator, value_type&&)): Add overload for rvalues.
* include/debug/multimap.h (multimap::insert(value_type&&))
(multimap::insert(const_iterator, value_type&&)): Likewise.
* include/debug/unordered_map (unordered_map::insert(value_type&&))
(unordered_map::insert(const_iterator, value_type&&))
(unordered_multimap::insert(value_type&&))
(unordered_multimap::insert(const_iterator, value_type&&)): Likewise.
* testsuite/23_containers/map/modifiers/insert/dr2354.cc (test02): New.
* testsuite/23_containers/multimap/modifiers/insert/dr2354.cc (test02):
New.
* testsuite/23_containers/unordered_map/insert/dr2354.cc (test02): New.
* testsuite/23_containers/unordered_multimap/insert/dr2354.cc (test02):
New.
2017-12-14 Jonathan Wakely <jwakely@redhat.com> 2017-12-14 Jonathan Wakely <jwakely@redhat.com>
PR libstdc++/83427 PR libstdc++/83427

View File

@ -260,6 +260,15 @@ namespace __debug
} }
#if __cplusplus >= 201103L #if __cplusplus >= 201103L
// _GLIBCXX_RESOLVE_LIB_DEFECTS
// 2354. Unnecessary copying when inserting into maps with braced-init
std::pair<iterator, bool>
insert(value_type&& __x)
{
auto __res = _Base::insert(std::move(__x));
return { iterator(__res.first, this), __res.second };
}
template<typename _Pair, typename = typename template<typename _Pair, typename = typename
std::enable_if<std::is_constructible<value_type, std::enable_if<std::is_constructible<value_type,
_Pair&&>::value>::type> _Pair&&>::value>::type>
@ -291,6 +300,15 @@ namespace __debug
} }
#if __cplusplus >= 201103L #if __cplusplus >= 201103L
// _GLIBCXX_RESOLVE_LIB_DEFECTS
// 2354. Unnecessary copying when inserting into maps with braced-init
iterator
insert(const_iterator __position, value_type&& __x)
{
__glibcxx_check_insert(__position);
return { _Base::insert(__position.base(), std::move(__x)), this };
}
template<typename _Pair, typename = typename template<typename _Pair, typename = typename
std::enable_if<std::is_constructible<value_type, std::enable_if<std::is_constructible<value_type,
_Pair&&>::value>::type> _Pair&&>::value>::type>

View File

@ -244,6 +244,12 @@ namespace __debug
{ return iterator(_Base::insert(__x), this); } { return iterator(_Base::insert(__x), this); }
#if __cplusplus >= 201103L #if __cplusplus >= 201103L
// _GLIBCXX_RESOLVE_LIB_DEFECTS
// 2354. Unnecessary copying when inserting into maps with braced-init
iterator
insert(value_type&& __x)
{ return { _Base::insert(std::move(__x)), this }; }
template<typename _Pair, typename = typename template<typename _Pair, typename = typename
std::enable_if<std::is_constructible<value_type, std::enable_if<std::is_constructible<value_type,
_Pair&&>::value>::type> _Pair&&>::value>::type>
@ -270,6 +276,15 @@ namespace __debug
} }
#if __cplusplus >= 201103L #if __cplusplus >= 201103L
// _GLIBCXX_RESOLVE_LIB_DEFECTS
// 2354. Unnecessary copying when inserting into maps with braced-init
iterator
insert(const_iterator __position, value_type&& __x)
{
__glibcxx_check_insert(__position);
return { _Base::insert(__position.base(), std::move(__x)), this };
}
template<typename _Pair, typename = typename template<typename _Pair, typename = typename
std::enable_if<std::is_constructible<value_type, std::enable_if<std::is_constructible<value_type,
_Pair&&>::value>::type> _Pair&&>::value>::type>

View File

@ -312,19 +312,20 @@ namespace __debug
insert(const value_type& __obj) insert(const value_type& __obj)
{ {
size_type __bucket_count = this->bucket_count(); size_type __bucket_count = this->bucket_count();
std::pair<_Base_iterator, bool> __res = _Base::insert(__obj); auto __res = _Base::insert(__obj);
_M_check_rehashed(__bucket_count); _M_check_rehashed(__bucket_count);
return std::make_pair(iterator(__res.first, this), __res.second); return { iterator(__res.first, this), __res.second };
} }
iterator // _GLIBCXX_RESOLVE_LIB_DEFECTS
insert(const_iterator __hint, const value_type& __obj) // 2354. Unnecessary copying when inserting into maps with braced-init
std::pair<iterator, bool>
insert(value_type&& __x)
{ {
__glibcxx_check_insert(__hint);
size_type __bucket_count = this->bucket_count(); size_type __bucket_count = this->bucket_count();
_Base_iterator __it = _Base::insert(__hint.base(), __obj); auto __res = _Base::insert(std::move(__x));
_M_check_rehashed(__bucket_count); _M_check_rehashed(__bucket_count);
return iterator(__it, this); return { iterator(__res.first, this), __res.second };
} }
template<typename _Pair, typename = typename template<typename _Pair, typename = typename
@ -340,6 +341,28 @@ namespace __debug
return std::make_pair(iterator(__res.first, this), __res.second); return std::make_pair(iterator(__res.first, this), __res.second);
} }
iterator
insert(const_iterator __hint, const value_type& __obj)
{
__glibcxx_check_insert(__hint);
size_type __bucket_count = this->bucket_count();
_Base_iterator __it = _Base::insert(__hint.base(), __obj);
_M_check_rehashed(__bucket_count);
return iterator(__it, this);
}
// _GLIBCXX_RESOLVE_LIB_DEFECTS
// 2354. Unnecessary copying when inserting into maps with braced-init
iterator
insert(const_iterator __hint, value_type&& __x)
{
__glibcxx_check_insert(__hint);
size_type __bucket_count = this->bucket_count();
auto __it = _Base::insert(__hint.base(), std::move(__x));
_M_check_rehashed(__bucket_count);
return iterator(__it, this);
}
template<typename _Pair, typename = typename template<typename _Pair, typename = typename
std::enable_if<std::is_constructible<value_type, std::enable_if<std::is_constructible<value_type,
_Pair&&>::value>::type> _Pair&&>::value>::type>
@ -907,6 +930,17 @@ namespace __debug
return iterator(__it, this); return iterator(__it, this);
} }
// _GLIBCXX_RESOLVE_LIB_DEFECTS
// 2354. Unnecessary copying when inserting into maps with braced-init
iterator
insert(value_type&& __x)
{
size_type __bucket_count = this->bucket_count();
auto __it = _Base::insert(std::move(__x));
_M_check_rehashed(__bucket_count);
return { __it, this };
}
iterator iterator
insert(const_iterator __hint, const value_type& __obj) insert(const_iterator __hint, const value_type& __obj)
{ {
@ -917,6 +951,18 @@ namespace __debug
return iterator(__it, this); return iterator(__it, this);
} }
// _GLIBCXX_RESOLVE_LIB_DEFECTS
// 2354. Unnecessary copying when inserting into maps with braced-init
iterator
insert(const_iterator __hint, value_type&& __x)
{
__glibcxx_check_insert(__hint);
size_type __bucket_count = this->bucket_count();
auto __it = _Base::insert(__hint.base(), std::move(__x));
_M_check_rehashed(__bucket_count);
return iterator(__it, this);
}
template<typename _Pair, typename = typename template<typename _Pair, typename = typename
std::enable_if<std::is_constructible<value_type, std::enable_if<std::is_constructible<value_type,
_Pair&&>::value>::type> _Pair&&>::value>::type>

View File

@ -30,3 +30,10 @@ test01()
std::map<int, MoveOnly> m; std::map<int, MoveOnly> m;
m.insert({1, 2}); // PR libstdc++/82522 - LWG 2354 m.insert({1, 2}); // PR libstdc++/82522 - LWG 2354
} }
void
test02()
{
std::map<int, MoveOnly> m;
m.insert(m.begin(), {1, 2}); // PR libstdc++/82522 - LWG 2354
}

View File

@ -30,3 +30,10 @@ test01()
std::multimap<int, MoveOnly> m; std::multimap<int, MoveOnly> m;
m.insert({1, 2}); // PR libstdc++/82522 - LWG 2354 m.insert({1, 2}); // PR libstdc++/82522 - LWG 2354
} }
void
test02()
{
std::multimap<int, MoveOnly> m;
m.insert(m.begin(), {1, 2}); // PR libstdc++/82522 - LWG 2354
}

View File

@ -30,3 +30,10 @@ test01()
std::unordered_map<int, MoveOnly> m; std::unordered_map<int, MoveOnly> m;
m.insert({1, 2}); // PR libstdc++/82522 - LWG 2354 m.insert({1, 2}); // PR libstdc++/82522 - LWG 2354
} }
void
test02()
{
std::unordered_map<int, MoveOnly> m;
m.insert(m.begin(), {1, 2}); // PR libstdc++/82522 - LWG 2354
}

View File

@ -30,3 +30,10 @@ test01()
std::unordered_multimap<int, MoveOnly> m; std::unordered_multimap<int, MoveOnly> m;
m.insert({1, 2}); // PR libstdc++/82522 - LWG 2354 m.insert({1, 2}); // PR libstdc++/82522 - LWG 2354
} }
void
test02()
{
std::unordered_multimap<int, MoveOnly> m;
m.insert(m.begin(), {1, 2}); // PR libstdc++/82522 - LWG 2354
}