From cf4a3f0859d315e3c09a8697bfaf17aac20d5561 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Dumont?= Date: Thu, 28 Dec 2017 05:37:54 +0000 Subject: [PATCH] backport: re PR libstdc++/82522 (std::map::insert(value_type &&) not selected) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 2017-12-28 François Dumont Backport from mainline 2017-12-20 François Dumont 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 --- libstdc++-v3/ChangeLog | 21 +++++++ libstdc++-v3/include/debug/map.h | 18 ++++++ libstdc++-v3/include/debug/multimap.h | 15 +++++ libstdc++-v3/include/debug/unordered_map | 60 ++++++++++++++++--- .../map/modifiers/insert/dr2354.cc | 7 +++ .../multimap/modifiers/insert/dr2354.cc | 7 +++ .../unordered_map/insert/dr2354.cc | 7 +++ .../unordered_multimap/insert/dr2354.cc | 7 +++ 8 files changed, 135 insertions(+), 7 deletions(-) diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index 5fbf3d67b42..563b769f200 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,3 +1,24 @@ +2017-12-28 François Dumont + + Backport from mainline + 2017-12-20 François Dumont + + 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 PR libstdc++/83427 diff --git a/libstdc++-v3/include/debug/map.h b/libstdc++-v3/include/debug/map.h index c275979052c..ba6a6201f8e 100644 --- a/libstdc++-v3/include/debug/map.h +++ b/libstdc++-v3/include/debug/map.h @@ -260,6 +260,15 @@ namespace __debug } #if __cplusplus >= 201103L + // _GLIBCXX_RESOLVE_LIB_DEFECTS + // 2354. Unnecessary copying when inserting into maps with braced-init + std::pair + insert(value_type&& __x) + { + auto __res = _Base::insert(std::move(__x)); + return { iterator(__res.first, this), __res.second }; + } + template::value>::type> @@ -291,6 +300,15 @@ namespace __debug } #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::value>::type> diff --git a/libstdc++-v3/include/debug/multimap.h b/libstdc++-v3/include/debug/multimap.h index f971cfa41f0..08fc73012c8 100644 --- a/libstdc++-v3/include/debug/multimap.h +++ b/libstdc++-v3/include/debug/multimap.h @@ -244,6 +244,12 @@ namespace __debug { return iterator(_Base::insert(__x), this); } #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::value>::type> @@ -270,6 +276,15 @@ namespace __debug } #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::value>::type> diff --git a/libstdc++-v3/include/debug/unordered_map b/libstdc++-v3/include/debug/unordered_map index 51a55ae21f3..658712815e3 100644 --- a/libstdc++-v3/include/debug/unordered_map +++ b/libstdc++-v3/include/debug/unordered_map @@ -312,19 +312,20 @@ namespace __debug insert(const value_type& __obj) { 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); - return std::make_pair(iterator(__res.first, this), __res.second); + return { iterator(__res.first, this), __res.second }; } - iterator - insert(const_iterator __hint, const value_type& __obj) + // _GLIBCXX_RESOLVE_LIB_DEFECTS + // 2354. Unnecessary copying when inserting into maps with braced-init + std::pair + insert(value_type&& __x) { - __glibcxx_check_insert(__hint); 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); - return iterator(__it, this); + return { iterator(__res.first, this), __res.second }; } templatebucket_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::value>::type> @@ -907,6 +930,17 @@ namespace __debug 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 insert(const_iterator __hint, const value_type& __obj) { @@ -917,6 +951,18 @@ namespace __debug 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::value>::type> diff --git a/libstdc++-v3/testsuite/23_containers/map/modifiers/insert/dr2354.cc b/libstdc++-v3/testsuite/23_containers/map/modifiers/insert/dr2354.cc index 338d9fd3f1e..cc0fcbb4677 100644 --- a/libstdc++-v3/testsuite/23_containers/map/modifiers/insert/dr2354.cc +++ b/libstdc++-v3/testsuite/23_containers/map/modifiers/insert/dr2354.cc @@ -30,3 +30,10 @@ test01() std::map m; m.insert({1, 2}); // PR libstdc++/82522 - LWG 2354 } + +void +test02() +{ + std::map m; + m.insert(m.begin(), {1, 2}); // PR libstdc++/82522 - LWG 2354 +} diff --git a/libstdc++-v3/testsuite/23_containers/multimap/modifiers/insert/dr2354.cc b/libstdc++-v3/testsuite/23_containers/multimap/modifiers/insert/dr2354.cc index ca743ec4ce9..73cbf4cf6d4 100644 --- a/libstdc++-v3/testsuite/23_containers/multimap/modifiers/insert/dr2354.cc +++ b/libstdc++-v3/testsuite/23_containers/multimap/modifiers/insert/dr2354.cc @@ -30,3 +30,10 @@ test01() std::multimap m; m.insert({1, 2}); // PR libstdc++/82522 - LWG 2354 } + +void +test02() +{ + std::multimap m; + m.insert(m.begin(), {1, 2}); // PR libstdc++/82522 - LWG 2354 +} diff --git a/libstdc++-v3/testsuite/23_containers/unordered_map/insert/dr2354.cc b/libstdc++-v3/testsuite/23_containers/unordered_map/insert/dr2354.cc index fe5356594c3..3507efa34a2 100644 --- a/libstdc++-v3/testsuite/23_containers/unordered_map/insert/dr2354.cc +++ b/libstdc++-v3/testsuite/23_containers/unordered_map/insert/dr2354.cc @@ -30,3 +30,10 @@ test01() std::unordered_map m; m.insert({1, 2}); // PR libstdc++/82522 - LWG 2354 } + +void +test02() +{ + std::unordered_map m; + m.insert(m.begin(), {1, 2}); // PR libstdc++/82522 - LWG 2354 +} diff --git a/libstdc++-v3/testsuite/23_containers/unordered_multimap/insert/dr2354.cc b/libstdc++-v3/testsuite/23_containers/unordered_multimap/insert/dr2354.cc index 5a27242c4e0..ff661132a09 100644 --- a/libstdc++-v3/testsuite/23_containers/unordered_multimap/insert/dr2354.cc +++ b/libstdc++-v3/testsuite/23_containers/unordered_multimap/insert/dr2354.cc @@ -30,3 +30,10 @@ test01() std::unordered_multimap m; m.insert({1, 2}); // PR libstdc++/82522 - LWG 2354 } + +void +test02() +{ + std::unordered_multimap m; + m.insert(m.begin(), {1, 2}); // PR libstdc++/82522 - LWG 2354 +}