From: Paolo Carlini Date: Tue, 15 May 2012 10:00:19 +0000 (+0000) Subject: re PR libstdc++/53339 (unordered_map::iterator requires Value to be complete type) X-Git-Tag: releases/gcc-4.8.0~5490 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=5ac4e73a1dc07f019feee9eceb39f0937ba25b8c;p=thirdparty%2Fgcc.git re PR libstdc++/53339 (unordered_map::iterator requires Value to be complete type) 2012-05-15 Paolo Carlini 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 --- diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index f1dab1ab1f64..874eab87fbc5 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,3 +1,22 @@ +2012-05-15 Paolo Carlini + + 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 PR libstdc++/53263 diff --git a/libstdc++-v3/include/bits/hashtable.h b/libstdc++-v3/include/bits/hashtable.h index 9a7954949169..f5bc3583f22a 100644 --- a/libstdc++-v3/include/bits/hashtable.h +++ b/libstdc++-v3/include/bits/hashtable.h @@ -203,8 +203,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION using __key_extract = typename std::conditional< __constant_iterators::value, - std::_Identity, - std::_Select1st>::type; + __detail::_Identity, + __detail::_Select1st>::type; using __hashtable_base = __detail:: _Hashtable_base<_Key, _Value, _ExtractKey, diff --git a/libstdc++-v3/include/bits/hashtable_policy.h b/libstdc++-v3/include/bits/hashtable_policy.h index a42d3d3179a1..708ef985675f 100644 --- a/libstdc++-v3/include/bits/hashtable_policy.h +++ b/libstdc++-v3/include/bits/hashtable_policy.h @@ -86,6 +86,23 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION noexcept(declval()(declval()))> { }; + struct _Identity + { + template + _Tp&& + operator()(_Tp&& __x) const + { return std::forward<_Tp>(__x); } + }; + + struct _Select1st + { + template + 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 // and iterators. @@ -497,27 +514,27 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION template - struct _Map_base<_Key, _Pair, _Alloc, std::_Select1st<_Pair>, _Equal, + struct _Map_base<_Key, _Pair, _Alloc, _Select1st, _Equal, _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. template - struct _Map_base<_Key, _Pair, _Alloc, std::_Select1st<_Pair>, _Equal, + struct _Map_base<_Key, _Pair, _Alloc, _Select1st, _Equal, _H1, _H2, _Hash, _RehashPolicy, _Traits, true> { private: using __hashtable_base = __detail::_Hashtable_base<_Key, _Pair, - std::_Select1st<_Pair>, + _Select1st, _Equal, _H1, _H2, _Hash, _Traits>; using __hashtable = _Hashtable<_Key, _Pair, _Alloc, - std::_Select1st<_Pair>, _Equal, + _Select1st, _Equal, _H1, _H2, _Hash, _RehashPolicy, _Traits>; using __hash_code = typename __hashtable_base::__hash_code; @@ -526,7 +543,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION public: using key_type = typename __hashtable_base::key_type; 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& operator[](const key_type& __k); @@ -546,10 +563,10 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION template - typename _Map_base<_Key, _Pair, _Alloc, std::_Select1st<_Pair>, _Equal, + typename _Map_base<_Key, _Pair, _Alloc, _Select1st, _Equal, _H1, _H2, _Hash, _RehashPolicy, _Traits, true> ::mapped_type& - _Map_base<_Key, _Pair, _Alloc, std::_Select1st<_Pair>, _Equal, + _Map_base<_Key, _Pair, _Alloc, _Select1st, _Equal, _H1, _H2, _Hash, _RehashPolicy, _Traits, true>:: operator[](const key_type& __k) { @@ -567,10 +584,10 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION template - typename _Map_base<_Key, _Pair, _Alloc, std::_Select1st<_Pair>, _Equal, + typename _Map_base<_Key, _Pair, _Alloc, _Select1st, _Equal, _H1, _H2, _Hash, _RehashPolicy, _Traits, true> ::mapped_type& - _Map_base<_Key, _Pair, _Alloc, std::_Select1st<_Pair>, _Equal, + _Map_base<_Key, _Pair, _Alloc, _Select1st, _Equal, _H1, _H2, _Hash, _RehashPolicy, _Traits, true>:: operator[](key_type&& __k) { @@ -589,10 +606,10 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION template - typename _Map_base<_Key, _Pair, _Alloc, std::_Select1st<_Pair>, _Equal, + typename _Map_base<_Key, _Pair, _Alloc, _Select1st, _Equal, _H1, _H2, _Hash, _RehashPolicy, _Traits, true> ::mapped_type& - _Map_base<_Key, _Pair, _Alloc, std::_Select1st<_Pair>, _Equal, + _Map_base<_Key, _Pair, _Alloc, _Select1st, _Equal, _H1, _H2, _Hash, _RehashPolicy, _Traits, true>:: at(const key_type& __k) { @@ -609,11 +626,10 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION template - const typename _Map_base<_Key, _Pair, _Alloc, std::_Select1st<_Pair>, - _Equal, - _H1, _H2, _Hash, _RehashPolicy, _Traits, true> - ::mapped_type& - _Map_base<_Key, _Pair, _Alloc, std::_Select1st<_Pair>, _Equal, + const typename _Map_base<_Key, _Pair, _Alloc, _Select1st, + _Equal, _H1, _H2, _Hash, _RehashPolicy, + _Traits, true>::mapped_type& + _Map_base<_Key, _Pair, _Alloc, _Select1st, _Equal, _H1, _H2, _Hash, _RehashPolicy, _Traits, true>:: at(const key_type& __k) const { @@ -1492,8 +1508,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION iterator>::type; using __iconv_type = typename std::conditional<__unique_keys::value, - std::_Select1st<__ireturn_type>, - std::_Identity<__ireturn_type> + _Select1st, _Identity >::type; private: using _EqualEBO = _Hashtable_ebo_helper<0, _Equal>; diff --git a/libstdc++-v3/include/bits/stl_function.h b/libstdc++-v3/include/bits/stl_function.h index 33d5e709628e..42f5c1752b73 100644 --- a/libstdc++-v3/include/bits/stl_function.h +++ b/libstdc++-v3/include/bits/stl_function.h @@ -473,11 +473,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION template 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> -#endif { _Tp& operator()(_Tp& __x) const @@ -490,9 +486,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION template struct _Select1st -#ifndef __GXX_EXPERIMENTAL_CXX0X__ : public unary_function<_Pair, typename _Pair::first_type> -#endif { typename _Pair::first_type& operator()(_Pair& __x) const @@ -517,9 +511,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION template struct _Select2nd -#ifndef __GXX_EXPERIMENTAL_CXX0X__ : public unary_function<_Pair, typename _Pair::second_type> -#endif { typename _Pair::second_type& operator()(_Pair& __x) const diff --git a/libstdc++-v3/include/bits/unordered_map.h b/libstdc++-v3/include/bits/unordered_map.h index bd3e46d892b7..27703b6b9c03 100644 --- a/libstdc++-v3/include/bits/unordered_map.h +++ b/libstdc++-v3/include/bits/unordered_map.h @@ -45,12 +45,11 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER typename _Alloc = std::allocator >, typename _Tr = __umap_traits<__cache_default<_Key, _Hash>::value>> using __umap_hashtable = _Hashtable<_Key, std::pair, - _Alloc, - std::_Select1st>, - _Pred, _Hash, - __detail::_Mod_range_hashing, - __detail::_Default_ranged_hash, - __detail::_Prime_rehash_policy, _Tr>; + _Alloc, __detail::_Select1st, + _Pred, _Hash, + __detail::_Mod_range_hashing, + __detail::_Default_ranged_hash, + __detail::_Prime_rehash_policy, _Tr>; /// Base types for unordered_multimap. template @@ -63,8 +62,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER typename _Alloc = std::allocator >, typename _Tr = __ummap_traits<__cache_default<_Key, _Hash>::value>> using __ummap_hashtable = _Hashtable<_Key, std::pair, - _Alloc, - std::_Select1st>, + _Alloc, __detail::_Select1st, _Pred, _Hash, __detail::_Mod_range_hashing, __detail::_Default_ranged_hash, diff --git a/libstdc++-v3/include/bits/unordered_set.h b/libstdc++-v3/include/bits/unordered_set.h index 32b606a16cd4..88179475623b 100644 --- a/libstdc++-v3/include/bits/unordered_set.h +++ b/libstdc++-v3/include/bits/unordered_set.h @@ -44,7 +44,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER typename _Alloc = std::allocator<_Value>, typename _Tr = __uset_traits<__cache_default<_Value, _Hash>::value>> using __uset_hashtable = _Hashtable<_Value, _Value, _Alloc, - std::_Identity<_Value>, _Pred, _Hash, + __detail::_Identity, _Pred, _Hash, __detail::_Mod_range_hashing, __detail::_Default_ranged_hash, __detail::_Prime_rehash_policy, _Tr>; @@ -59,7 +59,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER typename _Alloc = std::allocator<_Value>, typename _Tr = __umset_traits<__cache_default<_Value, _Hash>::value>> using __umset_hashtable = _Hashtable<_Value, _Value, _Alloc, - std::_Identity<_Value>, + __detail::_Identity, _Pred, _Hash, __detail::_Mod_range_hashing, __detail::_Default_ranged_hash, diff --git a/libstdc++-v3/include/ext/functional b/libstdc++-v3/include/ext/functional index f8402c16dc60..c981da0cb716 100644 --- a/libstdc++-v3/include/ext/functional +++ b/libstdc++-v3/include/ext/functional @@ -184,12 +184,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION */ template struct identity -#ifdef __GXX_EXPERIMENTAL_CXX0X__ - : public std::unary_function<_Tp,_Tp>, - public std::_Identity<_Tp> {}; -#else : public std::_Identity<_Tp> {}; -#endif /** @c select1st and @c select2nd are extensions provided by SGI. Their * @c operator()s @@ -204,22 +199,13 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION /// An \link SGIextensions SGI extension \endlink. template struct select1st -#ifdef __GXX_EXPERIMENTAL_CXX0X__ - : public std::unary_function<_Pair, typename _Pair::first_type>, - public std::_Select1st<_Pair> {}; -#else : public std::_Select1st<_Pair> {}; -#endif /// An \link SGIextensions SGI extension \endlink. template struct select2nd -#ifdef __GXX_EXPERIMENTAL_CXX0X__ - : public std::unary_function<_Pair, typename _Pair::second_type>, - public std::_Select2nd<_Pair> {}; -#else : public std::_Select2nd<_Pair> {}; -#endif + /** @} */ // extension documented next diff --git a/libstdc++-v3/testsuite/20_util/ratio/cons/cons_overflow_neg.cc b/libstdc++-v3/testsuite/20_util/ratio/cons/cons_overflow_neg.cc index d2694e29c4cf..a6881dbcf820 100644 --- a/libstdc++-v3/testsuite/20_util/ratio/cons/cons_overflow_neg.cc +++ b/libstdc++-v3/testsuite/20_util/ratio/cons/cons_overflow_neg.cc @@ -2,7 +2,7 @@ // { dg-options "-std=gnu++0x" } // { 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 // software; you can redistribute it and/or modify it under the @@ -51,5 +51,5 @@ test04() // { dg-error "required from here" "" { target *-*-* } 46 } // { dg-error "denominator cannot be zero" "" { target *-*-* } 265 } // { 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" } diff --git a/libstdc++-v3/testsuite/23_containers/unordered_map/requirements/53339.cc b/libstdc++-v3/testsuite/23_containers/unordered_map/requirements/53339.cc new file mode 100644 index 000000000000..809b10d5546b --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/unordered_map/requirements/53339.cc @@ -0,0 +1,34 @@ +// { 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 +// . + +#include + +struct LinkedHashMap +{ + struct Entry; + + typedef std::unordered_map Storage; + typedef Storage::iterator EntryPtr; + + struct Entry + { + EntryPtr prev, next; + }; +}; diff --git a/libstdc++-v3/testsuite/23_containers/unordered_multimap/requirements/53339.cc b/libstdc++-v3/testsuite/23_containers/unordered_multimap/requirements/53339.cc new file mode 100644 index 000000000000..92721333c50f --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/unordered_multimap/requirements/53339.cc @@ -0,0 +1,34 @@ +// { 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 +// . + +#include + +struct LinkedHashMap +{ + struct Entry; + + typedef std::unordered_multimap Storage; + typedef Storage::iterator EntryPtr; + + struct Entry + { + EntryPtr prev, next; + }; +};