From: Benjamin Kosnik Date: Wed, 24 Nov 2010 16:33:14 +0000 (+0000) Subject: tuple: Mark more constructors constexpr. X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=094a14eff78e4f2a4830b80416642dd247e6ad8e;p=gcc.git tuple: Mark more constructors constexpr. 2010-11-24 Benjamin Kosnik * include/std/tuple: Mark more constructors constexpr. * include/bits/stl_pair.h: Same. * testsuite/20_util/tuple/requirements/dr801.cc: New. * testsuite/20_util/pair/requirements/dr801.cc: New. * testsuite/20_util/tuple/cons/constexpr.cc: Add cases for new constexpr constructors. * testsuite/20_util/pair/cons/constexpr.cc: Same. * testsuite/20_util/pair/comparison_operators/constexpr.cc: New. * testsuite/20_util/weak_ptr/comparison/cmp_neg.cc: Adjust line number. From-SVN: r167118 --- diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index f18c7328f1c..bf498c36ffc 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,3 +1,16 @@ +2010-11-24 Benjamin Kosnik + + * include/std/tuple: Mark more constructors constexpr. + * include/bits/stl_pair.h: Same. + * testsuite/20_util/tuple/requirements/dr801.cc: New. + * testsuite/20_util/pair/requirements/dr801.cc: New. + * testsuite/20_util/tuple/cons/constexpr.cc: Add cases for new + constexpr constructors. + * testsuite/20_util/pair/cons/constexpr.cc: Same. + * testsuite/20_util/pair/comparison_operators/constexpr.cc: New. + + * testsuite/20_util/weak_ptr/comparison/cmp_neg.cc: Adjust line number. + 2010-11-24 Paolo Carlini * testsuite/30_threads/future/cons/constexpr.cc: Add dg-require* diff --git a/libstdc++-v3/include/bits/stl_pair.h b/libstdc++-v3/include/bits/stl_pair.h index 0e651e7ba76..c6753f6d5d9 100644 --- a/libstdc++-v3/include/bits/stl_pair.h +++ b/libstdc++-v3/include/bits/stl_pair.h @@ -98,63 +98,67 @@ _GLIBCXX_BEGIN_NAMESPACE(std) : first(), second() { } /** Two objects may be passed to a @c pair constructor to be copied. */ - pair(const _T1& __a, const _T2& __b) + _GLIBCXX_CONSTEXPR pair(const _T1& __a, const _T2& __b) : first(__a), second(__b) { } + /** There is also a templated copy ctor for the @c pair class itself. */ + template + _GLIBCXX_CONSTEXPR pair(const pair<_U1, _U2>& __p) + : first(__p.first), second(__p.second) { } + #ifdef __GXX_EXPERIMENTAL_CXX0X__ - pair(const pair&) = default; + constexpr pair(const pair&) = default; + + // Implicit. + // pair(pair&&) = default; // DR 811. template::value>::type> - pair(_U1&& __x, const _T2& __y) - : first(std::forward<_U1>(__x)), - second(__y) { } + pair(_U1&& __x, const _T2& __y) + : first(std::forward<_U1>(__x)), second(__y) { } template::value>::type> - pair(const _T1& __x, _U2&& __y) - : first(__x), - second(std::forward<_U2>(__y)) { } + pair(const _T1& __x, _U2&& __y) + : first(__x), second(std::forward<_U2>(__y)) { } template::value && std::is_convertible<_U2, _T2>::value>::type> - pair(_U1&& __x, _U2&& __y) - : first(std::forward<_U1>(__x)), - second(std::forward<_U2>(__y)) { } + pair(_U1&& __x, _U2&& __y) + : first(std::forward<_U1>(__x)), second(std::forward<_U2>(__y)) { } - template - pair(piecewise_construct_t, - tuple<_Args1...> __first_args, - tuple<_Args2...> __second_args) - : first(__cons(std::move(__first_args))), - second(__cons(std::move(__second_args))) { } -#endif - - /** There is also a templated copy ctor for the @c pair class itself. */ template - pair(const pair<_U1, _U2>& __p) - : first(__p.first), - second(__p.second) { } - -#ifdef __GXX_EXPERIMENTAL_CXX0X__ - template - pair(pair<_U1, _U2>&& __p) + pair(pair<_U1, _U2>&& __p) : first(std::forward<_U1>(__p.first)), second(std::forward<_U2>(__p.second)) { } + template + pair(piecewise_construct_t, + tuple<_Args1...> __first, tuple<_Args2...> __second) + : first(__cons(std::move(__first))), + second(__cons(std::move(__second))) { } + + pair& + operator=(const pair& __p) + { + first = __p.first; + second = __p.second; + return *this; + } + pair& operator=(pair&& __p) - { + { first = std::move(__p.first); second = std::move(__p.second); return *this; } template - pair& - operator=(const pair<_U1, _U2>& __p) + pair& + operator=(const pair<_U1, _U2>& __p) { first = __p.first; second = __p.second; @@ -162,8 +166,8 @@ _GLIBCXX_BEGIN_NAMESPACE(std) } template - pair& - operator=(pair<_U1, _U2>&& __p) + pair& + operator=(pair<_U1, _U2>&& __p) { first = std::move(__p.first); second = std::move(__p.second); @@ -175,54 +179,54 @@ _GLIBCXX_BEGIN_NAMESPACE(std) { using std::swap; swap(first, __p.first); - swap(second, __p.second); + swap(second, __p.second); } private: template - static _Tp - __cons(tuple<_Args...>&&); + static _Tp + __cons(tuple<_Args...>&&); template - static _Tp - __do_cons(tuple<_Args...>&&, const _Index_tuple<_Indexes...>&); + static _Tp + __do_cons(tuple<_Args...>&&, const _Index_tuple<_Indexes...>&); #endif }; /// Two pairs of the same type are equal iff their members are equal. template - inline bool + inline _GLIBCXX_CONSTEXPR bool operator==(const pair<_T1, _T2>& __x, const pair<_T1, _T2>& __y) { return __x.first == __y.first && __x.second == __y.second; } /// template - inline bool + inline _GLIBCXX_CONSTEXPR bool operator<(const pair<_T1, _T2>& __x, const pair<_T1, _T2>& __y) { return __x.first < __y.first || (!(__y.first < __x.first) && __x.second < __y.second); } /// Uses @c operator== to find the result. template - inline bool + inline _GLIBCXX_CONSTEXPR bool operator!=(const pair<_T1, _T2>& __x, const pair<_T1, _T2>& __y) { return !(__x == __y); } /// Uses @c operator< to find the result. template - inline bool + inline _GLIBCXX_CONSTEXPR bool operator>(const pair<_T1, _T2>& __x, const pair<_T1, _T2>& __y) { return __y < __x; } /// Uses @c operator< to find the result. template - inline bool + inline _GLIBCXX_CONSTEXPR bool operator<=(const pair<_T1, _T2>& __x, const pair<_T1, _T2>& __y) { return !(__y < __x); } /// Uses @c operator< to find the result. template - inline bool + inline _GLIBCXX_CONSTEXPR bool operator>=(const pair<_T1, _T2>& __x, const pair<_T1, _T2>& __y) { return !(__x < __y); } @@ -248,22 +252,23 @@ _GLIBCXX_BEGIN_NAMESPACE(std) */ // _GLIBCXX_RESOLVE_LIB_DEFECTS // 181. make_pair() unintended behavior -#ifndef __GXX_EXPERIMENTAL_CXX0X__ - template - inline pair<_T1, _T2> - make_pair(_T1 __x, _T2 __y) - { return pair<_T1, _T2>(__x, __y); } -#else +#ifdef __GXX_EXPERIMENTAL_CXX0X__ // NB: DR 706. template inline pair::__type, typename __decay_and_strip<_T2>::__type> make_pair(_T1&& __x, _T2&& __y) { - return pair::__type, - typename __decay_and_strip<_T2>::__type> - (std::forward<_T1>(__x), std::forward<_T2>(__y)); + typedef typename __decay_and_strip<_T1>::__type __ds_type1; + typedef typename __decay_and_strip<_T2>::__type __ds_type2; + typedef pair<__ds_type1, __ds_type2> __pair_type; + return __pair_type(std::forward<_T1>(__x), std::forward<_T2>(__y)); } +#else + template + inline pair<_T1, _T2> + make_pair(_T1 __x, _T2 __y) + { return pair<_T1, _T2>(__x, __y); } #endif _GLIBCXX_END_NAMESPACE diff --git a/libstdc++-v3/include/std/tuple b/libstdc++-v3/include/std/tuple index 682712104a2..df9ef1d1694 100644 --- a/libstdc++-v3/include/std/tuple +++ b/libstdc++-v3/include/std/tuple @@ -67,7 +67,7 @@ _GLIBCXX_BEGIN_NAMESPACE(std) constexpr _Head_base() : _Head() { } - _Head_base(const _Head& __h) + constexpr _Head_base(const _Head& __h) : _Head(__h) { } template @@ -77,7 +77,8 @@ _GLIBCXX_BEGIN_NAMESPACE(std) _Head& _M_head() { return *this; } const _Head& _M_head() const { return *this; } - void _M_swap_impl(_Head&) { /* no-op */ } + void + _M_swap_impl(_Head&) { /* no-op */ } }; template @@ -86,7 +87,7 @@ _GLIBCXX_BEGIN_NAMESPACE(std) constexpr _Head_base() : _M_head_impl() { } - _Head_base(const _Head& __h) + constexpr _Head_base(const _Head& __h) : _M_head_impl(__h) { } template @@ -151,7 +152,7 @@ _GLIBCXX_BEGIN_NAMESPACE(std) : _Inherited(), _Base() { } explicit - _Tuple_impl(const _Head& __head, const _Tail&... __tail) + constexpr _Tuple_impl(const _Head& __head, const _Tail&... __tail) : _Inherited(__tail...), _Base(__head) { } template @@ -160,10 +161,10 @@ _GLIBCXX_BEGIN_NAMESPACE(std) : _Inherited(std::forward<_UTail>(__tail)...), _Base(std::forward<_UHead>(__head)) { } - _Tuple_impl(const _Tuple_impl&) = default; + constexpr _Tuple_impl(const _Tuple_impl&) = default; _Tuple_impl(_Tuple_impl&& __in) - : _Inherited(std::move(__in._M_tail())), + : _Inherited(std::move(__in._M_tail())), _Base(std::forward<_Head>(__in._M_head())) { } template @@ -229,7 +230,7 @@ _GLIBCXX_BEGIN_NAMESPACE(std) : _Inherited() { } explicit - tuple(const _Elements&... __elements) + constexpr tuple(const _Elements&... __elements) : _Inherited(__elements...) { } template(__elements)...) { } - tuple(const tuple&) = default; + constexpr tuple(const tuple&) = default; tuple(tuple&& __in) : _Inherited(static_cast<_Inherited&&>(__in)) { } @@ -314,7 +315,7 @@ _GLIBCXX_BEGIN_NAMESPACE(std) : _Inherited() { } explicit - tuple(const _T1& __a1, const _T2& __a2) + constexpr tuple(const _T1& __a1, const _T2& __a2) : _Inherited(__a1, __a2) { } template @@ -322,7 +323,7 @@ _GLIBCXX_BEGIN_NAMESPACE(std) tuple(_U1&& __a1, _U2&& __a2) : _Inherited(std::forward<_U1>(__a1), std::forward<_U2>(__a2)) { } - tuple(const tuple&) = default; + constexpr tuple(const tuple&) = default; tuple(tuple&& __in) : _Inherited(static_cast<_Inherited&&>(__in)) { } @@ -412,7 +413,7 @@ _GLIBCXX_BEGIN_NAMESPACE(std) : _Inherited() { } explicit - tuple(const _T1& __a1) + constexpr tuple(const _T1& __a1) : _Inherited(__a1) { } template(__a1)) { } - tuple(const tuple&) = default; + constexpr tuple(const tuple&) = default; tuple(tuple&& __in) : _Inherited(static_cast<_Inherited&&>(__in)) { } template tuple(const tuple<_U1>& __in) - : _Inherited(static_cast&>(__in)) { } + : _Inherited(static_cast&>(__in)) { } template tuple(tuple<_U1>&& __in) diff --git a/libstdc++-v3/testsuite/20_util/pair/comparison_operators/constexpr.cc b/libstdc++-v3/testsuite/20_util/pair/comparison_operators/constexpr.cc new file mode 100644 index 00000000000..d5dc6e4e1df --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/pair/comparison_operators/constexpr.cc @@ -0,0 +1,29 @@ +// { dg-do compile } +// { dg-options "-std=gnu++0x" } + +// Copyright (C) 2010 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 +// . + +#include +#include + +int main() +{ + __gnu_test::constexpr_comparison_operators test; + test.operator()>(); + return 0; +} diff --git a/libstdc++-v3/testsuite/20_util/pair/cons/constexpr.cc b/libstdc++-v3/testsuite/20_util/pair/cons/constexpr.cc index 7bf6b71162d..1c854627ed4 100644 --- a/libstdc++-v3/testsuite/20_util/pair/cons/constexpr.cc +++ b/libstdc++-v3/testsuite/20_util/pair/cons/constexpr.cc @@ -23,7 +23,17 @@ int main() { - __gnu_test::constexpr_default_constructible test; - test.operator()>(); + __gnu_test::constexpr_default_constructible test1; + test1.operator()>(); + + __gnu_test::constexpr_single_value_constructible test2; + test2.operator(), std::pair>(); + test2.operator(), std::pair>(); + + // test 3 + const int i1(129); + const int i2(6); + constexpr std::pair p3(i1, i2); + return 0; } diff --git a/libstdc++-v3/testsuite/20_util/pair/requirements/dr801.cc b/libstdc++-v3/testsuite/20_util/pair/requirements/dr801.cc new file mode 100644 index 00000000000..36d380dcf87 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/pair/requirements/dr801.cc @@ -0,0 +1,52 @@ +// { dg-do compile } +// { dg-options "-std=gnu++0x" } + +// Copyright (C) 2010 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 +// . + +#include +#include + +// DR 801, pair and tuple vs. "passed in registers" +void test_trivial() +{ + // PODType, TType, NType, SLType, LType, NLType, LTypeDerived + typedef std::pair pair_type; + // static_assert(std::is_literal_type::value, "! literal"); + static_assert(std::has_trivial_copy_constructor::value, + "! triv copy"); + static_assert(std::has_trivial_destructor::value, + "! triv destructor"); + // static_assert(std::is_standard_layout::value, + // "! standard layout"); + + // Negative + /* + static_assert(std::has_trivial_default_constructor::value, + "! triv default"); + static_assert(std::has_trivial_copy_assign::value, + "! triv assign"); + static_assert(std::is_trivial::value, "! triv"); + static_assert(std::is_pod::value, "! pod"); + */ +} + +int main() +{ + test_trivial(); + return 0; +} diff --git a/libstdc++-v3/testsuite/20_util/tuple/cons/constexpr.cc b/libstdc++-v3/testsuite/20_util/tuple/cons/constexpr.cc index a4666e5d5cd..b5eba73fdac 100644 --- a/libstdc++-v3/testsuite/20_util/tuple/cons/constexpr.cc +++ b/libstdc++-v3/testsuite/20_util/tuple/cons/constexpr.cc @@ -23,7 +23,25 @@ int main() { - __gnu_test::constexpr_default_constructible test; - test.operator()>(); + __gnu_test::constexpr_default_constructible test1; + test1.operator()>(); + + __gnu_test::constexpr_single_value_constructible test2; + test2.operator(), std::tuple>(); + // test2.operator(), std::pair>(); + // test2.operator(), std::tuple>(); + // test2.operator(), std::tuple>(); + + // test 3 + const int i1(129); + const int i2(6); + constexpr std::tuple p3(i1, i2); + + // test 4 + const int i3(415); + const int i4(550); + const int i5(6414); + constexpr std::tuple p4(i1, i2, i3, i4, i5); + return 0; } diff --git a/libstdc++-v3/testsuite/20_util/tuple/requirements/dr801.cc b/libstdc++-v3/testsuite/20_util/tuple/requirements/dr801.cc new file mode 100644 index 00000000000..fd21b9ee5c5 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/tuple/requirements/dr801.cc @@ -0,0 +1,52 @@ +// { dg-do compile } +// { dg-options "-std=gnu++0x" } + +// Copyright (C) 2010 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 +// . + +#include +#include + +// DR 801, pair and tuple vs. "passed in registers" +void test_trivial() +{ + // PODType, TType, NType, SLType, LType, NLType, LTypeDerived + typedef std::tuple tuple_type; + // static_assert(std::is_literal_type::value, "! literal"); + static_assert(std::has_trivial_copy_constructor::value, + "! triv copy"); + static_assert(std::has_trivial_destructor::value, + "! triv destructor"); + // static_assert(std::is_standard_layout::value, + // "! standard layout"); + + // Negative + /* + static_assert(std::has_trivial_default_constructor::value, + "! triv default"); + static_assert(std::has_trivial_copy_assign::value, + "! triv assign"); + static_assert(std::is_trivial::value, "! triv"); + static_assert(std::is_pod::value, "! pod"); + */ +} + +int main() +{ + test_trivial(); + return 0; +} 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 f0a1f6cb1d4..7f5b109b61e 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 @@ -44,8 +44,8 @@ main() // { dg-warning "note" "" { target *-*-* } 350 } // { dg-warning "note" "" { target *-*-* } 1082 } // { dg-warning "note" "" { target *-*-* } 465 } -// { dg-warning "note" "" { target *-*-* } 580 } +// { dg-warning "note" "" { target *-*-* } 581 } // { dg-warning "note" "" { target *-*-* } 1027 } // { dg-warning "note" "" { target *-*-* } 340 } // { dg-warning "note" "" { target *-*-* } 290 } -// { dg-warning "note" "" { target *-*-* } 201 } +// { dg-warning "note" "" { target *-*-* } 205 }