]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
PR78134 fix return types of heterogeneous lookup functions
authorJonathan Wakely <jwakely@redhat.com>
Wed, 11 Jan 2017 14:44:15 +0000 (14:44 +0000)
committerJonathan Wakely <redi@gcc.gnu.org>
Wed, 11 Jan 2017 14:44:15 +0000 (14:44 +0000)
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

libstdc++-v3/ChangeLog
libstdc++-v3/include/bits/stl_map.h
libstdc++-v3/include/bits/stl_multimap.h
libstdc++-v3/include/bits/stl_multiset.h
libstdc++-v3/include/bits/stl_set.h
libstdc++-v3/testsuite/23_containers/map/operations/2.cc
libstdc++-v3/testsuite/23_containers/multimap/operations/2.cc
libstdc++-v3/testsuite/23_containers/multiset/operations/2.cc
libstdc++-v3/testsuite/23_containers/set/operations/2.cc

index b52d6dfc8c7e45836dace79c9d0f5f55f5331063..35fbb95f61780bb260554efd4c183320a4d5bcfd 100644 (file)
@@ -1,5 +1,19 @@
 2017-01-11  Jonathan Wakely  <jwakely@redhat.com>
 
+       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.
index 91b80d93e6b2ce8782f12fc71fa33649ad09bcea..194ce42e26306a5ad7ad78c4ad839e0d495cb17f 100644 (file)
@@ -1218,8 +1218,8 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
       template<typename _Kt>
        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<typename _Kt>
        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<typename _Kt>
        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<typename _Kt>
        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<typename _Kt>
        auto
        equal_range(const _Kt& __x)
-       -> decltype(_M_t._M_equal_range_tr(__x))
-       { return _M_t._M_equal_range_tr(__x); }
+       -> decltype(pair<iterator, iterator>(_M_t._M_equal_range_tr(__x)))
+       { return pair<iterator, iterator>(_M_t._M_equal_range_tr(__x)); }
 #endif
       //@}
 
@@ -1341,8 +1341,12 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
       template<typename _Kt>
        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<const_iterator, const_iterator>(
+             _M_t._M_equal_range_tr(__x)))
+       {
+         return pair<const_iterator, const_iterator>(
+             _M_t._M_equal_range_tr(__x));
+       }
 #endif
       //@}
 
index 98af1ba29fdc807712ca1eadf8ae3aab36e66e14..8b37de9686d5c6f23317c282f6388020c247a066 100644 (file)
@@ -887,8 +887,8 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
       template<typename _Kt>
        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<typename _Kt>
        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<typename _Kt>
        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<typename _Kt>
        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<typename _Kt>
        auto
        equal_range(const _Kt& __x)
-       -> decltype(_M_t._M_equal_range_tr(__x))
-       { return _M_t._M_equal_range_tr(__x); }
+       -> decltype(pair<iterator, iterator>(_M_t._M_equal_range_tr(__x)))
+       { return pair<iterator, iterator>(_M_t._M_equal_range_tr(__x)); }
 #endif
       //@}
 
@@ -1006,8 +1006,12 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
       template<typename _Kt>
        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<const_iterator, const_iterator>(
+             _M_t._M_equal_range_tr(__x)))
+       {
+         return pair<const_iterator, const_iterator>(
+             _M_t._M_equal_range_tr(__x));
+       }
 #endif
       //@}
 
index e2bc4f2aaec63cfcc4d82a14d81fa5e69a24cd21..871369c4a844ab9e51ee1c40728f786c0fb7fd7d 100644 (file)
@@ -785,14 +785,14 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
       template<typename _Kt>
        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<typename _Kt>
        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<typename _Kt>
        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<typename _Kt>
        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<typename _Kt>
        auto
        equal_range(const _Kt& __x)
-       -> decltype(_M_t._M_equal_range_tr(__x))
-       { return _M_t._M_equal_range_tr(__x); }
+       -> decltype(pair<iterator, iterator>(_M_t._M_equal_range_tr(__x)))
+       { return pair<iterator, iterator>(_M_t._M_equal_range_tr(__x)); }
 
       template<typename _Kt>
        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<iterator, iterator>(_M_t._M_equal_range_tr(__x)))
+       { return pair<iterator, iterator>(_M_t._M_equal_range_tr(__x)); }
 #endif
       //@}
 
index ab960f18810aa03aa1c4148262cb59a4b86893bb..3decaffbefab709ebf84d9e3431e403114a6a2aa 100644 (file)
@@ -804,14 +804,14 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
       template<typename _Kt>
        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<typename _Kt>
        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<typename _Kt>
        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<typename _Kt>
        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<typename _Kt>
        auto
        equal_range(const _Kt& __x)
-       -> decltype(_M_t._M_equal_range_tr(__x))
-       { return _M_t._M_equal_range_tr(__x); }
+       -> decltype(pair<iterator, iterator>(_M_t._M_equal_range_tr(__x)))
+       { return pair<iterator, iterator>(_M_t._M_equal_range_tr(__x)); }
 
       template<typename _Kt>
        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<iterator, iterator>(_M_t._M_equal_range_tr(__x)))
+       { return pair<iterator, iterator>(_M_t._M_equal_range_tr(__x)); }
 #endif
       //@}
 
index ef4e76b60e6fa447bada4f1b78a2b108e38628c8..a301025cdb965b4f685ea2ed5a2ec90e64705151 100644 (file)
@@ -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<decltype(it), test_type::iterator>::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<decltype(it), test_type::iterator>::value,
+      "lower_bound returns iterator");
+  static_assert(std::is_same<decltype(cit), test_type::const_iterator>::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<decltype(it), test_type::iterator>::value,
+      "upper_bound returns iterator");
+  static_assert(std::is_same<decltype(cit), test_type::const_iterator>::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<test_type::iterator, test_type::iterator>;
+  static_assert(std::is_same<decltype(it), pair>::value,
+      "equal_range returns pair<iterator, iterator>");
+  using cpair = std::pair<test_type::const_iterator, test_type::const_iterator>;
+  static_assert(std::is_same<decltype(cit), cpair>::value,
+      "const equal_range returns pair<const_iterator, const_iterator>");
 }
 
 void
index 06e084d4e7267ea5a070bce676c7b244a467243d..01a10f6fc20eade3f75842e550989dfbfc00840d 100644 (file)
@@ -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<decltype(it), test_type::iterator>::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<decltype(it), test_type::iterator>::value,
+      "lower_bound returns iterator");
+  static_assert(std::is_same<decltype(cit), test_type::const_iterator>::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<decltype(it), test_type::iterator>::value,
+      "upper_bound returns iterator");
+  static_assert(std::is_same<decltype(cit), test_type::const_iterator>::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<test_type::iterator, test_type::iterator>;
+  static_assert(std::is_same<decltype(it), pair>::value,
+      "equal_range returns pair<iterator, iterator>");
+  using cpair = std::pair<test_type::const_iterator, test_type::const_iterator>;
+  static_assert(std::is_same<decltype(cit), cpair>::value,
+      "const equal_range returns pair<const_iterator, const_iterator>");
 }
 
 
index 890016bcd2d7f84465eb47c3f1efbbd199dba952..9468151caf5cbc0887d221a7fb97d78a73a29e72 100644 (file)
@@ -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<decltype(it), test_type::iterator>::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<decltype(it), test_type::iterator>::value,
+      "lower_bound returns iterator");
+  static_assert(std::is_same<decltype(cit), test_type::const_iterator>::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<decltype(it), test_type::iterator>::value,
+      "upper_bound returns iterator");
+  static_assert(std::is_same<decltype(cit), test_type::const_iterator>::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<test_type::iterator, test_type::iterator>;
+  static_assert(std::is_same<decltype(it), pair>::value,
+      "equal_range returns pair<iterator, iterator>");
+  using cpair = std::pair<test_type::const_iterator, test_type::const_iterator>;
+  static_assert(std::is_same<decltype(cit), cpair>::value,
+      "const equal_range returns pair<const_iterator, const_iterator>");
 }
 
 
index aef808d31b245653f6725d59c66d662298918434..acddb18f5170055e90992931a872cd65b24e1025 100644 (file)
@@ -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<decltype(it), test_type::iterator>::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<decltype(it), test_type::iterator>::value,
+      "lower_bound returns iterator");
+  static_assert(std::is_same<decltype(cit), test_type::const_iterator>::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<decltype(it), test_type::iterator>::value,
+      "upper_bound returns iterator");
+  static_assert(std::is_same<decltype(cit), test_type::const_iterator>::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<test_type::iterator, test_type::iterator>;
+  static_assert(std::is_same<decltype(it), pair>::value,
+      "equal_range returns pair<iterator, iterator>");
+  using cpair = std::pair<test_type::const_iterator, test_type::const_iterator>;
+  static_assert(std::is_same<decltype(cit), cpair>::value,
+      "const equal_range returns pair<const_iterator, const_iterator>");
 }
 
 void