From: Jonathan Wakely Date: Tue, 14 Feb 2017 21:17:18 +0000 (+0000) Subject: PR78134 fix return types of heterogeneous lookup functions X-Git-Tag: releases/gcc-5.5.0~523 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ecf76b5d064f448941a569a83c93ccd1fd7f383b;p=thirdparty%2Fgcc.git PR78134 fix return types of heterogeneous lookup functions Backport from mainline 2017-01-11 Jonathan Wakely PR libstdc++/78134 * include/bits/stl_map.h (map::lower_bound, map::upper_bound) (map::equal_range): Fix return type of heterogeneous overloads. * include/bits/stl_multimap.h (multimap::lower_bound) (multimap::upper_bound, multimap::equal_range): Likewise. * include/bits/stl_multiset.h (multiset::lower_bound) (multiset::upper_bound, multiset::equal_range): Likewise. * include/bits/stl_set.h (set::lower_bound, set::upper_bound) (set::equal_range): Likewise. * testsuite/23_containers/map/operations/2.cc: Check return types. * testsuite/23_containers/multimap/operations/2.cc: Likewise. * testsuite/23_containers/multiset/operations/2.cc: Likewise. * testsuite/23_containers/set/operations/2.cc: Likewise. From-SVN: r245455 --- diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index 76d2dfcd1faf..8bccfc8f9cdc 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -3,6 +3,23 @@ Backport from mainline 2017-01-11 Jonathan Wakely + PR libstdc++/78134 + * include/bits/stl_map.h (map::lower_bound, map::upper_bound) + (map::equal_range): Fix return type of heterogeneous overloads. + * include/bits/stl_multimap.h (multimap::lower_bound) + (multimap::upper_bound, multimap::equal_range): Likewise. + * include/bits/stl_multiset.h (multiset::lower_bound) + (multiset::upper_bound, multiset::equal_range): Likewise. + * include/bits/stl_set.h (set::lower_bound, set::upper_bound) + (set::equal_range): Likewise. + * testsuite/23_containers/map/operations/2.cc: Check return types. + * testsuite/23_containers/multimap/operations/2.cc: Likewise. + * testsuite/23_containers/multiset/operations/2.cc: Likewise. + * testsuite/23_containers/set/operations/2.cc: Likewise. + + Backport from mainline + 2017-01-11 Jonathan Wakely + PR libstdc++/78273 * include/bits/stl_map.h (map::count<_Kt>(const _Kt&)): Don't assume the heterogeneous comparison can only find one match. diff --git a/libstdc++-v3/include/bits/stl_map.h b/libstdc++-v3/include/bits/stl_map.h index 89ba1d7a2ff8..1402607a13e7 100644 --- a/libstdc++-v3/include/bits/stl_map.h +++ b/libstdc++-v3/include/bits/stl_map.h @@ -920,8 +920,8 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER template auto lower_bound(const _Kt& __x) - -> decltype(_M_t._M_lower_bound_tr(__x)) - { return _M_t._M_lower_bound_tr(__x); } + -> decltype(iterator(_M_t._M_lower_bound_tr(__x))) + { return iterator(_M_t._M_lower_bound_tr(__x)); } #endif //@} @@ -945,8 +945,8 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER template auto lower_bound(const _Kt& __x) const - -> decltype(_M_t._M_lower_bound_tr(__x)) - { return _M_t._M_lower_bound_tr(__x); } + -> decltype(const_iterator(_M_t._M_lower_bound_tr(__x))) + { return const_iterator(_M_t._M_lower_bound_tr(__x)); } #endif //@} @@ -965,8 +965,8 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER template auto upper_bound(const _Kt& __x) - -> decltype(_M_t._M_upper_bound_tr(__x)) - { return _M_t._M_upper_bound_tr(__x); } + -> decltype(iterator(_M_t._M_upper_bound_tr(__x))) + { return iterator(_M_t._M_upper_bound_tr(__x)); } #endif //@} @@ -985,8 +985,8 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER template auto upper_bound(const _Kt& __x) const - -> decltype(_M_t._M_upper_bound_tr(__x)) - { return _M_t._M_upper_bound_tr(__x); } + -> decltype(const_iterator(_M_t._M_upper_bound_tr(__x))) + { return const_iterator(_M_t._M_upper_bound_tr(__x)); } #endif //@} @@ -1014,8 +1014,8 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER template auto equal_range(const _Kt& __x) - -> decltype(_M_t._M_equal_range_tr(__x)) - { return _M_t._M_equal_range_tr(__x); } + -> decltype(pair(_M_t._M_equal_range_tr(__x))) + { return pair(_M_t._M_equal_range_tr(__x)); } #endif //@} @@ -1043,8 +1043,12 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER template auto equal_range(const _Kt& __x) const - -> decltype(_M_t._M_equal_range_tr(__x)) - { return _M_t._M_equal_range_tr(__x); } + -> decltype(pair( + _M_t._M_equal_range_tr(__x))) + { + return pair( + _M_t._M_equal_range_tr(__x)); + } #endif //@} diff --git a/libstdc++-v3/include/bits/stl_multimap.h b/libstdc++-v3/include/bits/stl_multimap.h index 20076a1fd043..c6fd14262d8c 100644 --- a/libstdc++-v3/include/bits/stl_multimap.h +++ b/libstdc++-v3/include/bits/stl_multimap.h @@ -825,8 +825,8 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER template auto lower_bound(const _Kt& __x) - -> decltype(_M_t._M_lower_bound_tr(__x)) - { return _M_t._M_lower_bound_tr(__x); } + -> decltype(iterator(_M_t._M_lower_bound_tr(__x))) + { return iterator(_M_t._M_lower_bound_tr(__x)); } #endif //@} @@ -850,8 +850,8 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER template auto lower_bound(const _Kt& __x) const - -> decltype(_M_t._M_lower_bound_tr(__x)) - { return _M_t._M_lower_bound_tr(__x); } + -> decltype(const_iterator(_M_t._M_lower_bound_tr(__x))) + { return const_iterator(_M_t._M_lower_bound_tr(__x)); } #endif //@} @@ -870,8 +870,8 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER template auto upper_bound(const _Kt& __x) - -> decltype(_M_t._M_upper_bound_tr(__x)) - { return _M_t._M_upper_bound_tr(__x); } + -> decltype(iterator(_M_t._M_upper_bound_tr(__x))) + { return iterator(_M_t._M_upper_bound_tr(__x)); } #endif //@} @@ -890,8 +890,8 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER template auto upper_bound(const _Kt& __x) const - -> decltype(_M_t._M_upper_bound_tr(__x)) - { return _M_t._M_upper_bound_tr(__x); } + -> decltype(const_iterator(_M_t._M_upper_bound_tr(__x))) + { return const_iterator(_M_t._M_upper_bound_tr(__x)); } #endif //@} @@ -917,8 +917,8 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER template auto equal_range(const _Kt& __x) - -> decltype(_M_t._M_equal_range_tr(__x)) - { return _M_t._M_equal_range_tr(__x); } + -> decltype(pair(_M_t._M_equal_range_tr(__x))) + { return pair(_M_t._M_equal_range_tr(__x)); } #endif //@} @@ -944,8 +944,12 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER template auto equal_range(const _Kt& __x) const - -> decltype(_M_t._M_equal_range_tr(__x)) - { return _M_t._M_equal_range_tr(__x); } + -> decltype(pair( + _M_t._M_equal_range_tr(__x))) + { + return pair( + _M_t._M_equal_range_tr(__x)); + } #endif //@} diff --git a/libstdc++-v3/include/bits/stl_multiset.h b/libstdc++-v3/include/bits/stl_multiset.h index 3a947d53fba4..28d80f0cbc44 100644 --- a/libstdc++-v3/include/bits/stl_multiset.h +++ b/libstdc++-v3/include/bits/stl_multiset.h @@ -719,14 +719,14 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER template auto lower_bound(const _Kt& __x) - -> decltype(_M_t._M_lower_bound_tr(__x)) - { return _M_t._M_lower_bound_tr(__x); } + -> decltype(iterator(_M_t._M_lower_bound_tr(__x))) + { return iterator(_M_t._M_lower_bound_tr(__x)); } template auto lower_bound(const _Kt& __x) const - -> decltype(_M_t._M_lower_bound_tr(__x)) - { return _M_t._M_lower_bound_tr(__x); } + -> decltype(iterator(_M_t._M_lower_bound_tr(__x))) + { return iterator(_M_t._M_lower_bound_tr(__x)); } #endif //@} @@ -749,14 +749,14 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER template auto upper_bound(const _Kt& __x) - -> decltype(_M_t._M_upper_bound_tr(__x)) - { return _M_t._M_upper_bound_tr(__x); } + -> decltype(iterator(_M_t._M_upper_bound_tr(__x))) + { return iterator(_M_t._M_upper_bound_tr(__x)); } template auto upper_bound(const _Kt& __x) const - -> decltype(_M_t._M_upper_bound_tr(__x)) - { return _M_t._M_upper_bound_tr(__x); } + -> decltype(iterator(_M_t._M_upper_bound_tr(__x))) + { return iterator(_M_t._M_upper_bound_tr(__x)); } #endif //@} @@ -788,14 +788,14 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER template auto equal_range(const _Kt& __x) - -> decltype(_M_t._M_equal_range_tr(__x)) - { return _M_t._M_equal_range_tr(__x); } + -> decltype(pair(_M_t._M_equal_range_tr(__x))) + { return pair(_M_t._M_equal_range_tr(__x)); } template auto equal_range(const _Kt& __x) const - -> decltype(_M_t._M_equal_range_tr(__x)) - { return _M_t._M_equal_range_tr(__x); } + -> decltype(pair(_M_t._M_equal_range_tr(__x))) + { return pair(_M_t._M_equal_range_tr(__x)); } #endif //@} diff --git a/libstdc++-v3/include/bits/stl_set.h b/libstdc++-v3/include/bits/stl_set.h index 7c1c1c60a83b..c4cd597fca2c 100644 --- a/libstdc++-v3/include/bits/stl_set.h +++ b/libstdc++-v3/include/bits/stl_set.h @@ -738,14 +738,14 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER template auto lower_bound(const _Kt& __x) - -> decltype(_M_t._M_lower_bound_tr(__x)) - { return _M_t._M_lower_bound_tr(__x); } + -> decltype(iterator(_M_t._M_lower_bound_tr(__x))) + { return iterator(_M_t._M_lower_bound_tr(__x)); } template auto lower_bound(const _Kt& __x) const - -> decltype(_M_t._M_lower_bound_tr(__x)) - { return _M_t._M_lower_bound_tr(__x); } + -> decltype(const_iterator(_M_t._M_lower_bound_tr(__x))) + { return const_iterator(_M_t._M_lower_bound_tr(__x)); } #endif //@} @@ -768,14 +768,14 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER template auto upper_bound(const _Kt& __x) - -> decltype(_M_t._M_upper_bound_tr(__x)) - { return _M_t._M_upper_bound_tr(__x); } + -> decltype(iterator(_M_t._M_upper_bound_tr(__x))) + { return iterator(_M_t._M_upper_bound_tr(__x)); } template auto upper_bound(const _Kt& __x) const - -> decltype(_M_t._M_upper_bound_tr(__x)) - { return _M_t._M_upper_bound_tr(__x); } + -> decltype(iterator(_M_t._M_upper_bound_tr(__x))) + { return const_iterator(_M_t._M_upper_bound_tr(__x)); } #endif //@} @@ -807,14 +807,14 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER template auto equal_range(const _Kt& __x) - -> decltype(_M_t._M_equal_range_tr(__x)) - { return _M_t._M_equal_range_tr(__x); } + -> decltype(pair(_M_t._M_equal_range_tr(__x))) + { return pair(_M_t._M_equal_range_tr(__x)); } template auto equal_range(const _Kt& __x) const - -> decltype(_M_t._M_equal_range_tr(__x)) - { return _M_t._M_equal_range_tr(__x); } + -> decltype(pair(_M_t._M_equal_range_tr(__x))) + { return pair(_M_t._M_equal_range_tr(__x)); } #endif //@} diff --git a/libstdc++-v3/testsuite/23_containers/map/operations/2.cc b/libstdc++-v3/testsuite/23_containers/map/operations/2.cc index cbfd22322660..0613aa2105ae 100644 --- a/libstdc++-v3/testsuite/23_containers/map/operations/2.cc +++ b/libstdc++-v3/testsuite/23_containers/map/operations/2.cc @@ -53,7 +53,7 @@ test01() cit = cx.find(2L); VERIFY( cit == cx.end() ); - VERIFY( Cmp::count == 0); + VERIFY( Cmp::count == 0 ); static_assert(std::is_same::value, "find returns iterator"); @@ -76,7 +76,7 @@ test02() cn = cx.count(2L); VERIFY( cn == 0 ); - VERIFY( Cmp::count == 0); + VERIFY( Cmp::count == 0 ); } void @@ -94,7 +94,12 @@ test03() cit = cx.lower_bound(2L); VERIFY( cit != cx.end() && cit->second == '4' ); - VERIFY( Cmp::count == 0); + VERIFY( Cmp::count == 0 ); + + static_assert(std::is_same::value, + "lower_bound returns iterator"); + static_assert(std::is_same::value, + "const lower_bound returns const_iterator"); } void @@ -112,7 +117,12 @@ test04() cit = cx.upper_bound(3L); VERIFY( cit == cx.end() ); - VERIFY( Cmp::count == 0); + VERIFY( Cmp::count == 0 ); + + static_assert(std::is_same::value, + "upper_bound returns iterator"); + static_assert(std::is_same::value, + "const upper_bound returns const_iterator"); } void @@ -130,7 +140,14 @@ test05() cit = cx.equal_range(2L); VERIFY( cit.first == cit.second && cit.first != cx.end() ); - VERIFY( Cmp::count == 0); + VERIFY( Cmp::count == 0 ); + + using pair = std::pair; + static_assert(std::is_same::value, + "equal_range returns pair"); + using cpair = std::pair; + static_assert(std::is_same::value, + "const equal_range returns pair"); } void diff --git a/libstdc++-v3/testsuite/23_containers/multimap/operations/2.cc b/libstdc++-v3/testsuite/23_containers/multimap/operations/2.cc index eef6ee4515d7..99099c39e2c8 100644 --- a/libstdc++-v3/testsuite/23_containers/multimap/operations/2.cc +++ b/libstdc++-v3/testsuite/23_containers/multimap/operations/2.cc @@ -53,7 +53,7 @@ test01() cit = cx.find(2L); VERIFY( cit == cx.end() ); - VERIFY( Cmp::count == 0); + VERIFY( Cmp::count == 0 ); static_assert(std::is_same::value, "find returns iterator"); @@ -76,7 +76,7 @@ test02() cn = cx.count(2L); VERIFY( cn == 0 ); - VERIFY( Cmp::count == 0); + VERIFY( Cmp::count == 0 ); } void @@ -94,7 +94,12 @@ test03() cit = cx.lower_bound(2L); VERIFY( cit != cx.end() && cit->second == '4' ); - VERIFY( Cmp::count == 0); + VERIFY( Cmp::count == 0 ); + + static_assert(std::is_same::value, + "lower_bound returns iterator"); + static_assert(std::is_same::value, + "const lower_bound returns const_iterator"); } void @@ -112,7 +117,12 @@ test04() cit = cx.upper_bound(3L); VERIFY( cit == cx.end() ); - VERIFY( Cmp::count == 0); + VERIFY( Cmp::count == 0 ); + + static_assert(std::is_same::value, + "upper_bound returns iterator"); + static_assert(std::is_same::value, + "const upper_bound returns const_iterator"); } void @@ -131,7 +141,14 @@ test05() cit = cx.equal_range(2L); VERIFY( cit.first == cit.second && cit.first != cx.end() ); - VERIFY( Cmp::count == 0); + VERIFY( Cmp::count == 0 ); + + using pair = std::pair; + static_assert(std::is_same::value, + "equal_range returns pair"); + using cpair = std::pair; + static_assert(std::is_same::value, + "const equal_range returns pair"); } diff --git a/libstdc++-v3/testsuite/23_containers/multiset/operations/2.cc b/libstdc++-v3/testsuite/23_containers/multiset/operations/2.cc index 4bea719160f4..3123169d0353 100644 --- a/libstdc++-v3/testsuite/23_containers/multiset/operations/2.cc +++ b/libstdc++-v3/testsuite/23_containers/multiset/operations/2.cc @@ -53,7 +53,7 @@ test01() cit = cx.find(2L); VERIFY( cit == cx.end() ); - VERIFY( Cmp::count == 0); + VERIFY( Cmp::count == 0 ); static_assert(std::is_same::value, "find returns iterator"); @@ -76,7 +76,7 @@ test02() cn = cx.count(2L); VERIFY( cn == 0 ); - VERIFY( Cmp::count == 0); + VERIFY( Cmp::count == 0 ); } void @@ -94,7 +94,12 @@ test03() cit = cx.lower_bound(2L); VERIFY( cit != cx.end() && *cit == 3 ); - VERIFY( Cmp::count == 0); + VERIFY( Cmp::count == 0 ); + + static_assert(std::is_same::value, + "lower_bound returns iterator"); + static_assert(std::is_same::value, + "const lower_bound returns const_iterator"); } void @@ -112,7 +117,12 @@ test04() cit = cx.upper_bound(5L); VERIFY( cit == cx.end() ); - VERIFY( Cmp::count == 0); + VERIFY( Cmp::count == 0 ); + + static_assert(std::is_same::value, + "upper_bound returns iterator"); + static_assert(std::is_same::value, + "const upper_bound returns const_iterator"); } void @@ -131,7 +141,14 @@ test05() cit = cx.equal_range(2L); VERIFY( cit.first == cit.second && cit.first != cx.end() ); - VERIFY( Cmp::count == 0); + VERIFY( Cmp::count == 0 ); + + using pair = std::pair; + static_assert(std::is_same::value, + "equal_range returns pair"); + using cpair = std::pair; + static_assert(std::is_same::value, + "const equal_range returns pair"); } diff --git a/libstdc++-v3/testsuite/23_containers/set/operations/2.cc b/libstdc++-v3/testsuite/23_containers/set/operations/2.cc index 30355d4afafa..507aa955b29c 100644 --- a/libstdc++-v3/testsuite/23_containers/set/operations/2.cc +++ b/libstdc++-v3/testsuite/23_containers/set/operations/2.cc @@ -53,7 +53,7 @@ test01() cit = cx.find(2L); VERIFY( cit == cx.end() ); - VERIFY( Cmp::count == 0); + VERIFY( Cmp::count == 0 ); static_assert(std::is_same::value, "find returns iterator"); @@ -76,7 +76,7 @@ test02() cn = cx.count(2L); VERIFY( cn == 0 ); - VERIFY( Cmp::count == 0); + VERIFY( Cmp::count == 0 ); } void @@ -94,7 +94,12 @@ test03() cit = cx.lower_bound(2L); VERIFY( cit != cx.end() && *cit == 3 ); - VERIFY( Cmp::count == 0); + VERIFY( Cmp::count == 0 ); + + static_assert(std::is_same::value, + "lower_bound returns iterator"); + static_assert(std::is_same::value, + "const lower_bound returns const_iterator"); } void @@ -112,7 +117,12 @@ test04() cit = cx.upper_bound(5L); VERIFY( cit == cx.end() ); - VERIFY( Cmp::count == 0); + VERIFY( Cmp::count == 0 ); + + static_assert(std::is_same::value, + "upper_bound returns iterator"); + static_assert(std::is_same::value, + "const upper_bound returns const_iterator"); } void @@ -130,7 +140,14 @@ test05() cit = cx.equal_range(2L); VERIFY( cit.first == cit.second && cit.first != cx.end() ); - VERIFY( Cmp::count == 0); + VERIFY( Cmp::count == 0 ); + + using pair = std::pair; + static_assert(std::is_same::value, + "equal_range returns pair"); + using cpair = std::pair; + static_assert(std::is_same::value, + "const equal_range returns pair"); } void