From: Jonathan Wakely Date: Wed, 11 Jan 2017 14:44:15 +0000 (+0000) Subject: PR78134 fix return types of heterogeneous lookup functions X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=b744bf4e18d4c1422cdffbfeed30490252b3f64e;p=gcc.git PR78134 fix return types of heterogeneous lookup functions 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 * testsuite/23_containers/multimap/operations/2.cc * testsuite/23_containers/multiset/operations/2.cc * testsuite/23_containers/set/operations/2.cc From-SVN: r244318 --- diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index b52d6dfc8c7..35fbb95f617 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,5 +1,19 @@ 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 + * testsuite/23_containers/multimap/operations/2.cc + * testsuite/23_containers/multiset/operations/2.cc + * testsuite/23_containers/set/operations/2.cc + 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 91b80d93e6b..194ce42e263 100644 --- a/libstdc++-v3/include/bits/stl_map.h +++ b/libstdc++-v3/include/bits/stl_map.h @@ -1218,8 +1218,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 //@} @@ -1243,8 +1243,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 //@} @@ -1263,8 +1263,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 //@} @@ -1283,8 +1283,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 //@} @@ -1312,8 +1312,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 //@} @@ -1341,8 +1341,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 98af1ba29fd..8b37de9686d 100644 --- a/libstdc++-v3/include/bits/stl_multimap.h +++ b/libstdc++-v3/include/bits/stl_multimap.h @@ -887,8 +887,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 //@} @@ -912,8 +912,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 //@} @@ -932,8 +932,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 //@} @@ -952,8 +952,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 //@} @@ -979,8 +979,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 //@} @@ -1006,8 +1006,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 e2bc4f2aaec..871369c4a84 100644 --- a/libstdc++-v3/include/bits/stl_multiset.h +++ b/libstdc++-v3/include/bits/stl_multiset.h @@ -785,14 +785,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 //@} @@ -815,14 +815,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 //@} @@ -854,14 +854,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 ab960f18810..3decaffbefa 100644 --- a/libstdc++-v3/include/bits/stl_set.h +++ b/libstdc++-v3/include/bits/stl_set.h @@ -804,14 +804,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 //@} @@ -834,14 +834,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 //@} @@ -873,14 +873,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 ef4e76b60e6..a301025cdb9 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 06e084d4e72..01a10f6fc20 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 890016bcd2d..9468151caf5 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 aef808d31b2..acddb18f517 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