Commit 5ac4e73a by Paolo Carlini Committed by Paolo Carlini

re PR libstdc++/53339 (unordered_map::iterator requires Value to be complete type)

2012-05-15  Paolo Carlini  <paolo.carlini@oracle.com>

	PR libstdc++/53339
	* include/bits/hashtable_policy.h (__detail::_Identity,
	__detail::_Select1st): Add.
	(_Map_base, _Hashtable_base): Use the latter, adjust parameters.
	* include/bits/hashtable.h (_Hashtable::__key_extract): Adjust.
	* include/bits/unordered_set.h (__uset_hashtable, __umset_hashtable):
	Likewise.
	* include/bits/unordered_map.h (__umap_hashtable, __ummap_hashtable):
	Likewise.
	* include/bits/stl_function.h (_Identity, _Select1st, _Select2nd)
	Unconditionally derive from unary_function.
	* include/ext/functional (identity, select1st, select2nd): Remove
	#ifdef __GXX_EXPERIMENTAL_CXX0X__ bits.
	* testsuite/23_containers/unordered_map/requirements/53339.cc: New.
	* testsuite/23_containers/unordered_multimap/requirements/
	53339.cc: Likewise.

From-SVN: r187515
parent 23adb371
2012-05-15 Paolo Carlini <paolo.carlini@oracle.com>
PR libstdc++/53339
* include/bits/hashtable_policy.h (__detail::_Identity,
__detail::_Select1st): Add.
(_Map_base, _Hashtable_base): Use the latter, adjust parameters.
* include/bits/hashtable.h (_Hashtable::__key_extract): Adjust.
* include/bits/unordered_set.h (__uset_hashtable, __umset_hashtable):
Likewise.
* include/bits/unordered_map.h (__umap_hashtable, __ummap_hashtable):
Likewise.
* include/bits/stl_function.h (_Identity, _Select1st, _Select2nd)
Unconditionally derive from unary_function.
* include/ext/functional (identity, select1st, select2nd): Remove
#ifdef __GXX_EXPERIMENTAL_CXX0X__ bits.
* testsuite/23_containers/unordered_map/requirements/53339.cc: New.
* testsuite/23_containers/unordered_multimap/requirements/
53339.cc: Likewise.
2012-05-11 François Dumont <fdumont@gcc.gnu.org> 2012-05-11 François Dumont <fdumont@gcc.gnu.org>
PR libstdc++/53263 PR libstdc++/53263
......
...@@ -203,8 +203,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION ...@@ -203,8 +203,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
using __key_extract = typename std::conditional< using __key_extract = typename std::conditional<
__constant_iterators::value, __constant_iterators::value,
std::_Identity<value_type>, __detail::_Identity,
std::_Select1st<value_type>>::type; __detail::_Select1st>::type;
using __hashtable_base = __detail:: using __hashtable_base = __detail::
_Hashtable_base<_Key, _Value, _ExtractKey, _Hashtable_base<_Key, _Value, _ExtractKey,
......
...@@ -86,6 +86,23 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION ...@@ -86,6 +86,23 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
noexcept(declval<const _Hash&>()(declval<const _Key&>()))> noexcept(declval<const _Hash&>()(declval<const _Key&>()))>
{ }; { };
struct _Identity
{
template<typename _Tp>
_Tp&&
operator()(_Tp&& __x) const
{ return std::forward<_Tp>(__x); }
};
struct _Select1st
{
template<typename _Tp>
auto
operator()(_Tp&& __x) const
-> decltype(std::get<0>(std::forward<_Tp>(__x)))
{ return std::get<0>(std::forward<_Tp>(__x)); }
};
// Auxiliary types used for all instantiations of _Hashtable nodes // Auxiliary types used for all instantiations of _Hashtable nodes
// and iterators. // and iterators.
...@@ -497,27 +514,27 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION ...@@ -497,27 +514,27 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
template<typename _Key, typename _Pair, typename _Alloc, typename _Equal, template<typename _Key, typename _Pair, typename _Alloc, typename _Equal,
typename _H1, typename _H2, typename _Hash, typename _H1, typename _H2, typename _Hash,
typename _RehashPolicy, typename _Traits> typename _RehashPolicy, typename _Traits>
struct _Map_base<_Key, _Pair, _Alloc, std::_Select1st<_Pair>, _Equal, struct _Map_base<_Key, _Pair, _Alloc, _Select1st, _Equal,
_H1, _H2, _Hash, _RehashPolicy, _Traits, false> _H1, _H2, _Hash, _RehashPolicy, _Traits, false>
{ {
using mapped_type = typename _Pair::second_type; using mapped_type = typename std::tuple_element<1, _Pair>::type;
}; };
/// Partial specialization, __unique_keys set to true. /// Partial specialization, __unique_keys set to true.
template<typename _Key, typename _Pair, typename _Alloc, typename _Equal, template<typename _Key, typename _Pair, typename _Alloc, typename _Equal,
typename _H1, typename _H2, typename _Hash, typename _H1, typename _H2, typename _Hash,
typename _RehashPolicy, typename _Traits> typename _RehashPolicy, typename _Traits>
struct _Map_base<_Key, _Pair, _Alloc, std::_Select1st<_Pair>, _Equal, struct _Map_base<_Key, _Pair, _Alloc, _Select1st, _Equal,
_H1, _H2, _Hash, _RehashPolicy, _Traits, true> _H1, _H2, _Hash, _RehashPolicy, _Traits, true>
{ {
private: private:
using __hashtable_base = __detail::_Hashtable_base<_Key, _Pair, using __hashtable_base = __detail::_Hashtable_base<_Key, _Pair,
std::_Select1st<_Pair>, _Select1st,
_Equal, _H1, _H2, _Hash, _Equal, _H1, _H2, _Hash,
_Traits>; _Traits>;
using __hashtable = _Hashtable<_Key, _Pair, _Alloc, using __hashtable = _Hashtable<_Key, _Pair, _Alloc,
std::_Select1st<_Pair>, _Equal, _Select1st, _Equal,
_H1, _H2, _Hash, _RehashPolicy, _Traits>; _H1, _H2, _Hash, _RehashPolicy, _Traits>;
using __hash_code = typename __hashtable_base::__hash_code; using __hash_code = typename __hashtable_base::__hash_code;
...@@ -526,7 +543,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION ...@@ -526,7 +543,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
public: public:
using key_type = typename __hashtable_base::key_type; using key_type = typename __hashtable_base::key_type;
using iterator = typename __hashtable_base::iterator; using iterator = typename __hashtable_base::iterator;
using mapped_type = typename _Pair::second_type; using mapped_type = typename std::tuple_element<1, _Pair>::type;
mapped_type& mapped_type&
operator[](const key_type& __k); operator[](const key_type& __k);
...@@ -546,10 +563,10 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION ...@@ -546,10 +563,10 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
template<typename _Key, typename _Pair, typename _Alloc, typename _Equal, template<typename _Key, typename _Pair, typename _Alloc, typename _Equal,
typename _H1, typename _H2, typename _Hash, typename _H1, typename _H2, typename _Hash,
typename _RehashPolicy, typename _Traits> typename _RehashPolicy, typename _Traits>
typename _Map_base<_Key, _Pair, _Alloc, std::_Select1st<_Pair>, _Equal, typename _Map_base<_Key, _Pair, _Alloc, _Select1st, _Equal,
_H1, _H2, _Hash, _RehashPolicy, _Traits, true> _H1, _H2, _Hash, _RehashPolicy, _Traits, true>
::mapped_type& ::mapped_type&
_Map_base<_Key, _Pair, _Alloc, std::_Select1st<_Pair>, _Equal, _Map_base<_Key, _Pair, _Alloc, _Select1st, _Equal,
_H1, _H2, _Hash, _RehashPolicy, _Traits, true>:: _H1, _H2, _Hash, _RehashPolicy, _Traits, true>::
operator[](const key_type& __k) operator[](const key_type& __k)
{ {
...@@ -567,10 +584,10 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION ...@@ -567,10 +584,10 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
template<typename _Key, typename _Pair, typename _Alloc, typename _Equal, template<typename _Key, typename _Pair, typename _Alloc, typename _Equal,
typename _H1, typename _H2, typename _Hash, typename _H1, typename _H2, typename _Hash,
typename _RehashPolicy, typename _Traits> typename _RehashPolicy, typename _Traits>
typename _Map_base<_Key, _Pair, _Alloc, std::_Select1st<_Pair>, _Equal, typename _Map_base<_Key, _Pair, _Alloc, _Select1st, _Equal,
_H1, _H2, _Hash, _RehashPolicy, _Traits, true> _H1, _H2, _Hash, _RehashPolicy, _Traits, true>
::mapped_type& ::mapped_type&
_Map_base<_Key, _Pair, _Alloc, std::_Select1st<_Pair>, _Equal, _Map_base<_Key, _Pair, _Alloc, _Select1st, _Equal,
_H1, _H2, _Hash, _RehashPolicy, _Traits, true>:: _H1, _H2, _Hash, _RehashPolicy, _Traits, true>::
operator[](key_type&& __k) operator[](key_type&& __k)
{ {
...@@ -589,10 +606,10 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION ...@@ -589,10 +606,10 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
template<typename _Key, typename _Pair, typename _Alloc, typename _Equal, template<typename _Key, typename _Pair, typename _Alloc, typename _Equal,
typename _H1, typename _H2, typename _Hash, typename _H1, typename _H2, typename _Hash,
typename _RehashPolicy, typename _Traits> typename _RehashPolicy, typename _Traits>
typename _Map_base<_Key, _Pair, _Alloc, std::_Select1st<_Pair>, _Equal, typename _Map_base<_Key, _Pair, _Alloc, _Select1st, _Equal,
_H1, _H2, _Hash, _RehashPolicy, _Traits, true> _H1, _H2, _Hash, _RehashPolicy, _Traits, true>
::mapped_type& ::mapped_type&
_Map_base<_Key, _Pair, _Alloc, std::_Select1st<_Pair>, _Equal, _Map_base<_Key, _Pair, _Alloc, _Select1st, _Equal,
_H1, _H2, _Hash, _RehashPolicy, _Traits, true>:: _H1, _H2, _Hash, _RehashPolicy, _Traits, true>::
at(const key_type& __k) at(const key_type& __k)
{ {
...@@ -609,11 +626,10 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION ...@@ -609,11 +626,10 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
template<typename _Key, typename _Pair, typename _Alloc, typename _Equal, template<typename _Key, typename _Pair, typename _Alloc, typename _Equal,
typename _H1, typename _H2, typename _Hash, typename _H1, typename _H2, typename _Hash,
typename _RehashPolicy, typename _Traits> typename _RehashPolicy, typename _Traits>
const typename _Map_base<_Key, _Pair, _Alloc, std::_Select1st<_Pair>, const typename _Map_base<_Key, _Pair, _Alloc, _Select1st,
_Equal, _Equal, _H1, _H2, _Hash, _RehashPolicy,
_H1, _H2, _Hash, _RehashPolicy, _Traits, true> _Traits, true>::mapped_type&
::mapped_type& _Map_base<_Key, _Pair, _Alloc, _Select1st, _Equal,
_Map_base<_Key, _Pair, _Alloc, std::_Select1st<_Pair>, _Equal,
_H1, _H2, _Hash, _RehashPolicy, _Traits, true>:: _H1, _H2, _Hash, _RehashPolicy, _Traits, true>::
at(const key_type& __k) const at(const key_type& __k) const
{ {
...@@ -1492,8 +1508,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION ...@@ -1492,8 +1508,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
iterator>::type; iterator>::type;
using __iconv_type = typename std::conditional<__unique_keys::value, using __iconv_type = typename std::conditional<__unique_keys::value,
std::_Select1st<__ireturn_type>, _Select1st, _Identity
std::_Identity<__ireturn_type>
>::type; >::type;
private: private:
using _EqualEBO = _Hashtable_ebo_helper<0, _Equal>; using _EqualEBO = _Hashtable_ebo_helper<0, _Equal>;
......
...@@ -473,11 +473,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION ...@@ -473,11 +473,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
template<typename _Tp> template<typename _Tp>
struct _Identity struct _Identity
#ifndef __GXX_EXPERIMENTAL_CXX0X__
// unary_function itself is deprecated in C++11 and deriving from
// it can even be a nuisance (see PR 52942).
: public unary_function<_Tp,_Tp> : public unary_function<_Tp,_Tp>
#endif
{ {
_Tp& _Tp&
operator()(_Tp& __x) const operator()(_Tp& __x) const
...@@ -490,9 +486,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION ...@@ -490,9 +486,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
template<typename _Pair> template<typename _Pair>
struct _Select1st struct _Select1st
#ifndef __GXX_EXPERIMENTAL_CXX0X__
: public unary_function<_Pair, typename _Pair::first_type> : public unary_function<_Pair, typename _Pair::first_type>
#endif
{ {
typename _Pair::first_type& typename _Pair::first_type&
operator()(_Pair& __x) const operator()(_Pair& __x) const
...@@ -517,9 +511,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION ...@@ -517,9 +511,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
template<typename _Pair> template<typename _Pair>
struct _Select2nd struct _Select2nd
#ifndef __GXX_EXPERIMENTAL_CXX0X__
: public unary_function<_Pair, typename _Pair::second_type> : public unary_function<_Pair, typename _Pair::second_type>
#endif
{ {
typename _Pair::second_type& typename _Pair::second_type&
operator()(_Pair& __x) const operator()(_Pair& __x) const
......
...@@ -45,12 +45,11 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER ...@@ -45,12 +45,11 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
typename _Alloc = std::allocator<std::pair<const _Key, _Tp> >, typename _Alloc = std::allocator<std::pair<const _Key, _Tp> >,
typename _Tr = __umap_traits<__cache_default<_Key, _Hash>::value>> typename _Tr = __umap_traits<__cache_default<_Key, _Hash>::value>>
using __umap_hashtable = _Hashtable<_Key, std::pair<const _Key, _Tp>, using __umap_hashtable = _Hashtable<_Key, std::pair<const _Key, _Tp>,
_Alloc, _Alloc, __detail::_Select1st,
std::_Select1st<std::pair<const _Key, _Tp>>, _Pred, _Hash,
_Pred, _Hash, __detail::_Mod_range_hashing,
__detail::_Mod_range_hashing, __detail::_Default_ranged_hash,
__detail::_Default_ranged_hash, __detail::_Prime_rehash_policy, _Tr>;
__detail::_Prime_rehash_policy, _Tr>;
/// Base types for unordered_multimap. /// Base types for unordered_multimap.
template<bool _Cache> template<bool _Cache>
...@@ -63,8 +62,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER ...@@ -63,8 +62,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
typename _Alloc = std::allocator<std::pair<const _Key, _Tp> >, typename _Alloc = std::allocator<std::pair<const _Key, _Tp> >,
typename _Tr = __ummap_traits<__cache_default<_Key, _Hash>::value>> typename _Tr = __ummap_traits<__cache_default<_Key, _Hash>::value>>
using __ummap_hashtable = _Hashtable<_Key, std::pair<const _Key, _Tp>, using __ummap_hashtable = _Hashtable<_Key, std::pair<const _Key, _Tp>,
_Alloc, _Alloc, __detail::_Select1st,
std::_Select1st<std::pair<const _Key, _Tp>>,
_Pred, _Hash, _Pred, _Hash,
__detail::_Mod_range_hashing, __detail::_Mod_range_hashing,
__detail::_Default_ranged_hash, __detail::_Default_ranged_hash,
......
...@@ -44,7 +44,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER ...@@ -44,7 +44,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
typename _Alloc = std::allocator<_Value>, typename _Alloc = std::allocator<_Value>,
typename _Tr = __uset_traits<__cache_default<_Value, _Hash>::value>> typename _Tr = __uset_traits<__cache_default<_Value, _Hash>::value>>
using __uset_hashtable = _Hashtable<_Value, _Value, _Alloc, using __uset_hashtable = _Hashtable<_Value, _Value, _Alloc,
std::_Identity<_Value>, _Pred, _Hash, __detail::_Identity, _Pred, _Hash,
__detail::_Mod_range_hashing, __detail::_Mod_range_hashing,
__detail::_Default_ranged_hash, __detail::_Default_ranged_hash,
__detail::_Prime_rehash_policy, _Tr>; __detail::_Prime_rehash_policy, _Tr>;
...@@ -59,7 +59,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER ...@@ -59,7 +59,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
typename _Alloc = std::allocator<_Value>, typename _Alloc = std::allocator<_Value>,
typename _Tr = __umset_traits<__cache_default<_Value, _Hash>::value>> typename _Tr = __umset_traits<__cache_default<_Value, _Hash>::value>>
using __umset_hashtable = _Hashtable<_Value, _Value, _Alloc, using __umset_hashtable = _Hashtable<_Value, _Value, _Alloc,
std::_Identity<_Value>, __detail::_Identity,
_Pred, _Hash, _Pred, _Hash,
__detail::_Mod_range_hashing, __detail::_Mod_range_hashing,
__detail::_Default_ranged_hash, __detail::_Default_ranged_hash,
......
...@@ -184,12 +184,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION ...@@ -184,12 +184,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
*/ */
template <class _Tp> template <class _Tp>
struct identity struct identity
#ifdef __GXX_EXPERIMENTAL_CXX0X__
: public std::unary_function<_Tp,_Tp>,
public std::_Identity<_Tp> {};
#else
: public std::_Identity<_Tp> {}; : public std::_Identity<_Tp> {};
#endif
/** @c select1st and @c select2nd are extensions provided by SGI. Their /** @c select1st and @c select2nd are extensions provided by SGI. Their
* @c operator()s * @c operator()s
...@@ -204,22 +199,13 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION ...@@ -204,22 +199,13 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
/// An \link SGIextensions SGI extension \endlink. /// An \link SGIextensions SGI extension \endlink.
template <class _Pair> template <class _Pair>
struct select1st struct select1st
#ifdef __GXX_EXPERIMENTAL_CXX0X__
: public std::unary_function<_Pair, typename _Pair::first_type>,
public std::_Select1st<_Pair> {};
#else
: public std::_Select1st<_Pair> {}; : public std::_Select1st<_Pair> {};
#endif
/// An \link SGIextensions SGI extension \endlink. /// An \link SGIextensions SGI extension \endlink.
template <class _Pair> template <class _Pair>
struct select2nd struct select2nd
#ifdef __GXX_EXPERIMENTAL_CXX0X__
: public std::unary_function<_Pair, typename _Pair::second_type>,
public std::_Select2nd<_Pair> {};
#else
: public std::_Select2nd<_Pair> {}; : public std::_Select2nd<_Pair> {};
#endif
/** @} */ /** @} */
// extension documented next // extension documented next
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
// { dg-options "-std=gnu++0x" } // { dg-options "-std=gnu++0x" }
// { dg-require-cstdint "" } // { dg-require-cstdint "" }
// Copyright (C) 2008, 2009, 2010, 2011 Free Software Foundation // Copyright (C) 2008, 2009, 2010, 2011, 2012 Free Software Foundation
// //
// This file is part of the GNU ISO C++ Library. This library is free // This file is part of the GNU ISO C++ Library. This library is free
// software; you can redistribute it and/or modify it under the // software; you can redistribute it and/or modify it under the
...@@ -51,5 +51,5 @@ test04() ...@@ -51,5 +51,5 @@ test04()
// { dg-error "required from here" "" { target *-*-* } 46 } // { dg-error "required from here" "" { target *-*-* } 46 }
// { dg-error "denominator cannot be zero" "" { target *-*-* } 265 } // { dg-error "denominator cannot be zero" "" { target *-*-* } 265 }
// { dg-error "out of range" "" { target *-*-* } 266 } // { dg-error "out of range" "" { target *-*-* } 266 }
// { dg-error "overflow in constant expression" "" { target *-*-* } 61 } // { dg-error "overflow in constant expression" "" { target *-*-* } 62 }
// { dg-prune-output "not a member" } // { dg-prune-output "not a member" }
// { dg-do compile }
// { dg-options "-std=gnu++11" }
// Copyright (C) 2012 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
// software; you can redistribute it and/or modify it under the
// terms of the GNU General Public License as published by the
// Free Software Foundation; either version 3, or (at your option)
// any later version.
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without Pred the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License along
// with this library; see the file COPYING3. If not see
// <http://www.gnu.org/licenses/>.
#include <unordered_map>
struct LinkedHashMap
{
struct Entry;
typedef std::unordered_map<int, Entry> Storage;
typedef Storage::iterator EntryPtr;
struct Entry
{
EntryPtr prev, next;
};
};
// { dg-do compile }
// { dg-options "-std=gnu++11" }
// Copyright (C) 2012 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
// software; you can redistribute it and/or modify it under the
// terms of the GNU General Public License as published by the
// Free Software Foundation; either version 3, or (at your option)
// any later version.
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without Pred the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License along
// with this library; see the file COPYING3. If not see
// <http://www.gnu.org/licenses/>.
#include <unordered_map>
struct LinkedHashMap
{
struct Entry;
typedef std::unordered_multimap<int, Entry> Storage;
typedef Storage::iterator EntryPtr;
struct Entry
{
EntryPtr prev, next;
};
};
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment