From dd7b175ec31726b91aee02c4adbb63486b8fea5f Mon Sep 17 00:00:00 2001 From: Paolo Carlini Date: Tue, 31 May 2011 02:29:22 +0000 Subject: [PATCH] type_traits (__or_, __and_): Add trivial definitions for a single element. 2011-05-30 Paolo Carlini * include/std/type_traits (__or_, __and_): Add trivial definitions for a single element. * include/bits/stl_pair.h: Use __and_ in noexcept specs and constraints. (pair<>::pair(pair&&)): Define. (pair<>::pair(const pair<>&)): Constrain with is_convertible. (pair<>::pair(pair<>&&)): Likewise, remove noexcept. * include/std/tuple: Use __and_ in noexcept specs and constraints. (_Tuple_impl<>::_Tuple_impl(allocator_arg_t, const _Alloc&, _Tuple_impl&&)): Remove noexcept. (tuple<>::tuple(_UElements&&...), tuple(const tuple<_UElements...>&), tuple(tuple<_UElements...>&&), tuple(const pair<_U1, _U2>&), tuple(pair<_U1, _U2>&&)): Constrain with is_convertible. * testsuite/20_util/tuple/moveable2.cc: Use = delete. * testsuite/20_util/make_signed/requirements/typedefs_neg.cc: Adjust dg-error line numbers. * testsuite/20_util/make_unsigned/requirements/typedefs_neg.cc: Likewise. * testsuite/20_util/declval/requirements/1_neg.cc: Likewise. * testsuite/20_util/ratio/cons/cons_overflow_neg.cc: Likewise. * testsuite/20_util/weak_ptr/comparison/cmp_neg.cc: Likewise. From-SVN: r174464 --- libstdc++-v3/ChangeLog | 24 +++++ libstdc++-v3/include/bits/stl_pair.h | 44 +++++---- libstdc++-v3/include/std/tuple | 97 +++++++++++-------- libstdc++-v3/include/std/type_traits | 14 ++- .../20_util/declval/requirements/1_neg.cc | 2 +- .../make_signed/requirements/typedefs_neg.cc | 4 +- .../requirements/typedefs_neg.cc | 4 +- .../20_util/ratio/cons/cons_overflow_neg.cc | 2 +- .../testsuite/20_util/tuple/moveable2.cc | 8 +- .../20_util/weak_ptr/comparison/cmp_neg.cc | 4 +- 10 files changed, 132 insertions(+), 71 deletions(-) diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index e5fd280b1ed..ba7bd9cbc46 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,3 +1,27 @@ +2011-05-30 Paolo Carlini + + * include/std/type_traits (__or_, __and_): Add trivial definitions + for a single element. + * include/bits/stl_pair.h: Use __and_ in noexcept specs and + constraints. + (pair<>::pair(pair&&)): Define. + (pair<>::pair(const pair<>&)): Constrain with is_convertible. + (pair<>::pair(pair<>&&)): Likewise, remove noexcept. + * include/std/tuple: Use __and_ in noexcept specs and constraints. + (_Tuple_impl<>::_Tuple_impl(allocator_arg_t, const _Alloc&, + _Tuple_impl&&)): Remove noexcept. + (tuple<>::tuple(_UElements&&...), tuple(const tuple<_UElements...>&), + tuple(tuple<_UElements...>&&), tuple(const pair<_U1, _U2>&), + tuple(pair<_U1, _U2>&&)): Constrain with is_convertible. + * testsuite/20_util/tuple/moveable2.cc: Use = delete. + * testsuite/20_util/make_signed/requirements/typedefs_neg.cc: + Adjust dg-error line numbers. + * testsuite/20_util/make_unsigned/requirements/typedefs_neg.cc: + Likewise. + * testsuite/20_util/declval/requirements/1_neg.cc: Likewise. + * testsuite/20_util/ratio/cons/cons_overflow_neg.cc: Likewise. + * testsuite/20_util/weak_ptr/comparison/cmp_neg.cc: Likewise. + 2011-05-31 Jonathan Wakely * include/std/tuple: Restore is_convertible constraint. diff --git a/libstdc++-v3/include/bits/stl_pair.h b/libstdc++-v3/include/bits/stl_pair.h index fbb475b5132..61ebc719040 100644 --- a/libstdc++-v3/include/bits/stl_pair.h +++ b/libstdc++-v3/include/bits/stl_pair.h @@ -105,37 +105,47 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION : first(__a), second(__b) { } /** There is also a templated copy ctor for the @c pair class itself. */ +#ifndef __GXX_EXPERIMENTAL_CXX0X__ template - _GLIBCXX_CONSTEXPR pair(const pair<_U1, _U2>& __p) + pair(const pair<_U1, _U2>& __p) + : first(__p.first), second(__p.second) { } +#else + template, + is_convertible>::value>::type> + constexpr pair(const pair<_U1, _U2>& __p) : first(__p.first), second(__p.second) { } -#ifdef __GXX_EXPERIMENTAL_CXX0X__ constexpr pair(const pair&) = default; - // Implicit?!? Breaks containers!!! - // pair(pair&&) = default; + // XXX Defaulted?!? Breaks std::map!!! + pair(pair&& __p) + noexcept(__and_, + is_nothrow_move_constructible<_T2>>::value) + : first(std::forward(__p.first)), + second(std::forward(__p.second)) { } // DR 811. template::value>::type> + enable_if::value>::type> pair(_U1&& __x, const _T2& __y) : first(std::forward<_U1>(__x)), second(__y) { } template::value>::type> + enable_if::value>::type> pair(const _T1& __x, _U2&& __y) : first(__x), second(std::forward<_U2>(__y)) { } template::value - && std::is_convertible<_U2, _T2>::value>::type> + enable_if<__and_, + is_convertible<_U2, _T2>>::value>::type> pair(_U1&& __x, _U2&& __y) : first(std::forward<_U1>(__x)), second(std::forward<_U2>(__y)) { } - template + template, + is_convertible<_U2, _T2>>::value>::type> pair(pair<_U1, _U2>&& __p) - noexcept(std::is_nothrow_constructible<_T1, _U1&&>::value - && std::is_nothrow_constructible<_T2, _U2&&>::value) : first(std::forward<_U1>(__p.first)), second(std::forward<_U2>(__p.second)) { } @@ -155,11 +165,11 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION pair& operator=(pair&& __p) - noexcept(std::is_nothrow_move_assignable<_T1>::value - && std::is_nothrow_move_assignable<_T2>::value) + noexcept(__and_, + is_nothrow_move_assignable<_T2>>::value) { - first = std::move(__p.first); - second = std::move(__p.second); + first = std::forward(__p.first); + second = std::forward(__p.second); return *this; } @@ -176,8 +186,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION pair& operator=(pair<_U1, _U2>&& __p) { - first = std::move(__p.first); - second = std::move(__p.second); + first = std::forward<_U1>(__p.first); + second = std::forward<_U2>(__p.second); return *this; } diff --git a/libstdc++-v3/include/std/tuple b/libstdc++-v3/include/std/tuple index f8ec271c1c5..10272ccb1b2 100644 --- a/libstdc++-v3/include/std/tuple +++ b/libstdc++-v3/include/std/tuple @@ -224,7 +224,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION : _Inherited(__tail...), _Base(__head) { } template::type> + enable_if::type> explicit _Tuple_impl(_UHead&& __head, _UTail&&... __tail) : _Inherited(std::forward<_UTail>(__tail)...), @@ -233,8 +233,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION constexpr _Tuple_impl(const _Tuple_impl&) = default; _Tuple_impl(_Tuple_impl&& __in) - noexcept(std::is_nothrow_move_constructible<_Head>::value - && std::is_nothrow_move_constructible<_Inherited>::value) + noexcept(__and_, + is_nothrow_move_constructible<_Inherited>>::value) : _Inherited(std::move(__in._M_tail())), _Base(std::forward<_Head>(__in._M_head())) { } @@ -254,13 +254,13 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION template _Tuple_impl(allocator_arg_t __tag, const _Alloc& __a, - const _Head& __head, const _Tail&... __tail) + const _Head& __head, const _Tail&... __tail) : _Inherited(__tag, __a, __tail...), _Base(__use_alloc<_Head, _Alloc, _Head>(__a), __head) { } template::type> + typename = typename enable_if::type> _Tuple_impl(allocator_arg_t __tag, const _Alloc& __a, _UHead&& __head, _UTail&&... __tail) : _Inherited(__tag, __a, std::forward<_UTail>(__tail)...), @@ -276,8 +276,6 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION template _Tuple_impl(allocator_arg_t __tag, const _Alloc& __a, _Tuple_impl&& __in) - noexcept(std::is_nothrow_move_constructible<_Head>::value - && std::is_nothrow_move_constructible<_Inherited>::value) : _Inherited(__tag, __a, std::move(__in._M_tail())), _Base(__use_alloc<_Head, _Alloc, _Head>(__a), std::forward<_Head>(__in._M_head())) { } @@ -305,8 +303,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION _Tuple_impl& operator=(_Tuple_impl&& __in) - noexcept(std::is_nothrow_move_assignable<_Head>::value - && std::is_nothrow_move_assignable<_Inherited>::value) + noexcept(__and_, + is_nothrow_move_assignable<_Inherited>>::value) { _M_head() = std::forward<_Head>(__in._M_head()); _M_tail() = std::move(__in._M_tail()); @@ -359,9 +357,11 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION : _Inherited(__elements...) { } template::type> - explicit + enable_if<__and_, + __and_...>>::value>::type> + explicit tuple(_UElements&&... __elements) : _Inherited(std::forward<_UElements>(__elements)...) { } @@ -369,15 +369,19 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION tuple(tuple&&) = default; template::type> + enable_if<__and_, + __and_...>>::value>::type> tuple(const tuple<_UElements...>& __in) : _Inherited(static_cast&>(__in)) { } template::type> + enable_if<__and_, + __and_...>>::value>::type> tuple(tuple<_UElements...>&& __in) : _Inherited(static_cast<_Tuple_impl<0, _UElements...>&&>(__in)) { } @@ -393,8 +397,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION : _Inherited(__tag, __a, __elements...) { } template::type> + enable_if::type> tuple(allocator_arg_t __tag, const _Alloc& __a, _UElements&&... __elements) : _Inherited(__tag, __a, std::forward<_UElements>(__elements)...) @@ -409,8 +413,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION : _Inherited(__tag, __a, static_cast<_Inherited&&>(__in)) { } template::type> + enable_if::type> tuple(allocator_arg_t __tag, const _Alloc& __a, const tuple<_UElements...>& __in) : _Inherited(__tag, __a, @@ -418,8 +422,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION { } template::type> + enable_if::type> tuple(allocator_arg_t __tag, const _Alloc& __a, tuple<_UElements...>&& __in) : _Inherited(__tag, __a, @@ -435,15 +439,15 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION tuple& operator=(tuple&& __in) - noexcept(std::is_nothrow_move_assignable<_Inherited>::value) + noexcept(is_nothrow_move_assignable<_Inherited>::value) { static_cast<_Inherited&>(*this) = std::move(__in); return *this; } template::type> + enable_if::type> tuple& operator=(const tuple<_UElements...>& __in) { @@ -452,8 +456,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION } template::type> + enable_if::type> tuple& operator=(tuple<_UElements...>&& __in) { @@ -488,7 +492,9 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION constexpr tuple(const _T1& __a1, const _T2& __a2) : _Inherited(__a1, __a2) { } - template + template, + is_convertible<_U2, _T2>>::value>::type> explicit tuple(_U1&& __a1, _U2&& __a2) : _Inherited(std::forward<_U1>(__a1), std::forward<_U2>(__a2)) { } @@ -496,20 +502,28 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION constexpr tuple(const tuple&) = default; tuple(tuple&&) = default; - template + template, + is_convertible>::value>::type> tuple(const tuple<_U1, _U2>& __in) : _Inherited(static_cast&>(__in)) { } - template + template, + is_convertible<_U2, _T2>>::value>::type> tuple(tuple<_U1, _U2>&& __in) : _Inherited(static_cast<_Tuple_impl<0, _U1, _U2>&&>(__in)) { } - template + template, + is_convertible>::value>::type> tuple(const pair<_U1, _U2>& __in) : _Inherited(__in.first, __in.second) { } - template - tuple(pair<_U1, _U2>&& __in) + template, + is_convertible<_U2, _T2>>::value>::type> + tuple(pair<_U1, _U2>&& __in) : _Inherited(std::forward<_U1>(__in.first), std::forward<_U2>(__in.second)) { } @@ -568,7 +582,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION tuple& operator=(tuple&& __in) - noexcept(std::is_nothrow_move_assignable<_Inherited>::value) + noexcept(is_nothrow_move_assignable<_Inherited>::value) { static_cast<_Inherited&>(*this) = std::move(__in); return *this; @@ -615,6 +629,9 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION }; /// tuple (1-element). + // TODO: Should be simply removed when c++/49225 is fixed, worst case + // together with a different way to constrain the constructors + // of the primary template. template class tuple<_T1> : public _Tuple_impl<0, _T1> { @@ -629,7 +646,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION : _Inherited(__a1) { } template::value>::type> + enable_if::value>::type> explicit tuple(_U1&& __a1) : _Inherited(std::forward<_U1>(__a1)) { } @@ -637,11 +654,13 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION constexpr tuple(const tuple&) = default; tuple(tuple&&) = default; - template + template::value>::type> tuple(const tuple<_U1>& __in) : _Inherited(static_cast&>(__in)) { } - template + template::value>::type> tuple(tuple<_U1>&& __in) : _Inherited(static_cast<_Tuple_impl<0, _U1>&&>(__in)) { } @@ -686,7 +705,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION tuple& operator=(tuple&& __in) - noexcept(std::is_nothrow_move_assignable<_Inherited>::value) + noexcept(is_nothrow_move_assignable<_Inherited>::value) { static_cast<_Inherited&>(*this) = std::move(__in); return *this; diff --git a/libstdc++-v3/include/std/type_traits b/libstdc++-v3/include/std/type_traits index 184e28ba8dc..a8842eda95b 100644 --- a/libstdc++-v3/include/std/type_traits +++ b/libstdc++-v3/include/std/type_traits @@ -59,9 +59,14 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION template struct integral_constant; - template + template struct __or_; + template + struct __or_<_B1> + : public _B1 + { }; + template struct __or_<_B1, _B2> : public conditional<_B1::value, _B1, _B2>::type @@ -72,9 +77,14 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION : public conditional<_B1::value, _B1, __or_<_B2, _B3, _Bn...>>::type { }; - template + template struct __and_; + template + struct __and_<_B1> + : public _B1 + { }; + template struct __and_<_B1, _B2> : public conditional<_B1::value, _B2, _B1>::type diff --git a/libstdc++-v3/testsuite/20_util/declval/requirements/1_neg.cc b/libstdc++-v3/testsuite/20_util/declval/requirements/1_neg.cc index 3ca56e9c333..8fcdab40a58 100644 --- a/libstdc++-v3/testsuite/20_util/declval/requirements/1_neg.cc +++ b/libstdc++-v3/testsuite/20_util/declval/requirements/1_neg.cc @@ -19,7 +19,7 @@ // with this library; see the file COPYING3. If not see // . -// { dg-error "static assertion failed" "" { target *-*-* } 1715 } +// { dg-error "static assertion failed" "" { target *-*-* } 1725 } #include diff --git a/libstdc++-v3/testsuite/20_util/make_signed/requirements/typedefs_neg.cc b/libstdc++-v3/testsuite/20_util/make_signed/requirements/typedefs_neg.cc index c92df36b348..77328d8a4c2 100644 --- a/libstdc++-v3/testsuite/20_util/make_signed/requirements/typedefs_neg.cc +++ b/libstdc++-v3/testsuite/20_util/make_signed/requirements/typedefs_neg.cc @@ -48,5 +48,5 @@ void test01() // { dg-error "instantiated from here" "" { target *-*-* } 40 } // { dg-error "instantiated from here" "" { target *-*-* } 42 } -// { dg-error "invalid use of incomplete type" "" { target *-*-* } 1501 } -// { dg-error "declaration of" "" { target *-*-* } 1465 } +// { dg-error "invalid use of incomplete type" "" { target *-*-* } 1511 } +// { dg-error "declaration of" "" { target *-*-* } 1475 } diff --git a/libstdc++-v3/testsuite/20_util/make_unsigned/requirements/typedefs_neg.cc b/libstdc++-v3/testsuite/20_util/make_unsigned/requirements/typedefs_neg.cc index 2bb62cba715..572953eef27 100644 --- a/libstdc++-v3/testsuite/20_util/make_unsigned/requirements/typedefs_neg.cc +++ b/libstdc++-v3/testsuite/20_util/make_unsigned/requirements/typedefs_neg.cc @@ -48,5 +48,5 @@ void test01() // { dg-error "instantiated from here" "" { target *-*-* } 40 } // { dg-error "instantiated from here" "" { target *-*-* } 42 } -// { dg-error "invalid use of incomplete type" "" { target *-*-* } 1425 } -// { dg-error "declaration of" "" { target *-*-* } 1389 } +// { dg-error "invalid use of incomplete type" "" { target *-*-* } 1435 } +// { dg-error "declaration of" "" { target *-*-* } 1399 } 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 14076a2d121..e6a71c3fe5d 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 @@ -51,4 +51,4 @@ test04() // { dg-error "instantiated from here" "" { target *-*-* } 46 } // { dg-error "denominator cannot be zero" "" { target *-*-* } 268 } // { dg-error "out of range" "" { target *-*-* } 269 } -// { dg-error "overflow in constant expression" "" { target *-*-* } 99 } +// { dg-error "overflow in constant expression" "" { target *-*-* } 109 } diff --git a/libstdc++-v3/testsuite/20_util/tuple/moveable2.cc b/libstdc++-v3/testsuite/20_util/tuple/moveable2.cc index f0800742118..5ed8de56a69 100644 --- a/libstdc++-v3/testsuite/20_util/tuple/moveable2.cc +++ b/libstdc++-v3/testsuite/20_util/tuple/moveable2.cc @@ -1,6 +1,6 @@ // { dg-options "-std=gnu++0x" } -// Copyright (C) 2008, 2009 Free Software Foundation, Inc. +// Copyright (C) 2008, 2009, 2010, 2011 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 @@ -17,7 +17,6 @@ // with this library; see the file COPYING3. If not see // . - #include #include @@ -30,9 +29,8 @@ struct MoveOnly MoveOnly& operator=(MoveOnly&&) { return *this; } -private: - MoveOnly(MoveOnly const&); // = delete - MoveOnly& operator=(MoveOnly const&); // = delete + MoveOnly(MoveOnly const&) = delete; + MoveOnly& operator=(MoveOnly const&) = delete; }; MoveOnly diff --git a/libstdc++-v3/testsuite/20_util/weak_ptr/comparison/cmp_neg.cc b/libstdc++-v3/testsuite/20_util/weak_ptr/comparison/cmp_neg.cc index 040c196f437..ace80cf79c0 100644 --- a/libstdc++-v3/testsuite/20_util/weak_ptr/comparison/cmp_neg.cc +++ b/libstdc++-v3/testsuite/20_util/weak_ptr/comparison/cmp_neg.cc @@ -51,9 +51,9 @@ main() // { dg-warning "note" "" { target *-*-* } 485 } // { dg-warning "note" "" { target *-*-* } 479 } // { dg-warning "note" "" { target *-*-* } 469 } -// { dg-warning "note" "" { target *-*-* } 868 } +// { dg-warning "note" "" { target *-*-* } 887 } // { dg-warning "note" "" { target *-*-* } 1056 } // { dg-warning "note" "" { target *-*-* } 1050 } // { dg-warning "note" "" { target *-*-* } 342 } // { dg-warning "note" "" { target *-*-* } 292 } -// { dg-warning "note" "" { target *-*-* } 214 } +// { dg-warning "note" "" { target *-*-* } 224 }