diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index b4be6e59890..c8cdaaa04fb 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,5 +1,20 @@ 2017-01-20 Jonathan Wakely + PR libstdc++/72792 + PR libstdc++/72793 + * include/bits/alloc_traits.h (__allocator_traits_base::__rebind): + Replace with class template using void_t. + (__alloc_rebind): Define in terms of + __allocator_traits_base::__rebind. + (allocator_traits): Remove unconditional static_assert for + rebind_alloc. + * include/bits/ptr_traits.h (__replace_first_arg): Remove type member. + (pointer_traits::__rebind): Replace with class template using void_t. + (pointer_traits::rebind): Define in terms of __rebind. + (pointer_traits): Remove unconditional static_assert for rebind. + * testsuite/20_util/allocator_traits/members/rebind_alloc.cc: New test. + * testsuite/20_util/pointer_traits/rebind.cc: New test. + PR libstdc++/69321 * include/experimental/any (__any_caster): Avoid instantiating manager function for types that can't be stored in any. diff --git a/libstdc++-v3/include/bits/alloc_traits.h b/libstdc++-v3/include/bits/alloc_traits.h index fc8f053b55b..a8367111666 100644 --- a/libstdc++-v3/include/bits/alloc_traits.h +++ b/libstdc++-v3/include/bits/alloc_traits.h @@ -44,8 +44,13 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION struct __allocator_traits_base { - template - using __rebind = typename _Alloc::template rebind<_Up>::other; + template + struct __rebind : __replace_first_arg<_Tp, _Up> { }; + + template + struct __rebind<_Tp, _Up, + __void_t::other>> + { using type = typename _Tp::template rebind<_Up>::other; }; protected: template @@ -71,9 +76,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION }; template - using __alloc_rebind = __detected_or_t_<__replace_first_arg_t, - __allocator_traits_base::__rebind, - _Alloc, _Up>; + using __alloc_rebind + = typename __allocator_traits_base::template __rebind<_Alloc, _Up>::type; /** * @brief Uniform interface to all allocator types. @@ -184,9 +188,6 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION template using rebind_traits = allocator_traits>; - static_assert(!is_same, __undefined>::value, - "allocator defines rebind or is like Alloc"); - private: template static auto diff --git a/libstdc++-v3/include/bits/ptr_traits.h b/libstdc++-v3/include/bits/ptr_traits.h index 9fab9df867b..d390d04099e 100644 --- a/libstdc++-v3/include/bits/ptr_traits.h +++ b/libstdc++-v3/include/bits/ptr_traits.h @@ -56,7 +56,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION // Given Template and U return Template, otherwise invalid. template struct __replace_first_arg - { using type = __undefined; }; + { }; template class _Template, typename _Up, typename _Tp, typename... _Types> @@ -84,8 +84,12 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION template using __difference_type = typename _Tp::difference_type; + template + struct __rebind : __replace_first_arg<_Tp, _Up> { }; + template - using __rebind = typename _Tp::template rebind<_Up>; + struct __rebind<_Tp, _Up, __void_t>> + { using type = typename _Tp::template rebind<_Up>; }; public: /// The pointer type. @@ -101,8 +105,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION /// A pointer to a different type. template - using rebind - = __detected_or_t_<__replace_first_arg_t, __rebind, _Ptr, _Up>; + using rebind = typename __rebind<_Ptr, _Up>::type; static _Ptr pointer_to(__make_not_void& __e) @@ -110,8 +113,6 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION static_assert(!is_same::value, "pointer type defines element_type or is like SomePointer"); - static_assert(!is_same, __undefined>::value, - "pointer type defines rebind or is like SomePointer"); }; /** diff --git a/libstdc++-v3/testsuite/20_util/allocator_traits/members/rebind_alloc.cc b/libstdc++-v3/testsuite/20_util/allocator_traits/members/rebind_alloc.cc new file mode 100644 index 00000000000..60a62491143 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/allocator_traits/members/rebind_alloc.cc @@ -0,0 +1,81 @@ +// Copyright (C) 2017 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 even 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 +// . + +// { dg-do compile { target c++11 } } + +#include + +using std::is_same; + +template + using Rebind = typename std::allocator_traits::template rebind_alloc; + +template + struct HasRebind { + using value_type = T; + template struct rebind { using other = std::allocator; }; + }; + +static_assert(is_same, long>, + std::allocator>::value, + "nested alias template is used"); + +template + struct NoRebind0 { + using value_type = T; + }; + +static_assert(is_same, long>, + NoRebind0>::value, + "first template argument is replaced"); + +template + struct NoRebind1 { + using value_type = T; + }; + +static_assert(is_same, long>, + NoRebind1>::value, + "first template argument is replaced"); + +template + struct NoRebind2 { + using value_type = T; + }; + +static_assert(is_same, long>, + NoRebind2>::value, + "first template argument is replaced"); + +template + struct NoRebindN { + using value_type = T; + }; + +static_assert(is_same, long>, + NoRebindN>::value, + "first template argument is replaced"); +static_assert(is_same, long>, + NoRebindN>::value, + "first template argument is replaced"); + +template + struct CannotRebind { + using value_type = T; + }; +// PR libstdc++/72792 specialization of allocator_traits is still well-formed: +std::allocator_traits>::value_type v; diff --git a/libstdc++-v3/testsuite/20_util/pointer_traits/rebind.cc b/libstdc++-v3/testsuite/20_util/pointer_traits/rebind.cc new file mode 100644 index 00000000000..a62815988ed --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/pointer_traits/rebind.cc @@ -0,0 +1,68 @@ +// Copyright (C) 2017 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 even 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 +// . + +// { dg-do compile { target c++11 } } + +#include + +using std::is_same; + +template + using Rebind = typename std::pointer_traits::template rebind; + +template + struct HasRebind { + template using rebind = U*; + }; + +static_assert(is_same, long>, + long*>::value, + "nested alias template is used"); + +template struct NoRebind0 { }; + +static_assert(is_same, long>, + NoRebind0>::value, + "first template argument is replaced"); + +template struct NoRebind1 { }; + +static_assert(is_same, long>, + NoRebind1>::value, + "first template argument is replaced"); + +template struct NoRebind2 { }; + +static_assert(is_same, long>, + NoRebind2>::value, + "first template argument is replaced"); + +template struct NoRebindN { }; + +static_assert(is_same, long>, + NoRebindN>::value, + "first template argument is replaced"); +static_assert(is_same, long>, + NoRebindN>::value, + "first template argument is replaced"); + +template + struct CannotRebind { + using element_type = T; + }; +// PR libstdc++/72793 specialization of pointer_traits is still well-formed: +std::pointer_traits>::element_type e;