diff options
author | bkoz <bkoz@138bc75d-0d04-0410-961f-82ee72b054a4> | 2012-10-18 08:36:06 +0000 |
---|---|---|
committer | bkoz <bkoz@138bc75d-0d04-0410-961f-82ee72b054a4> | 2012-10-18 08:36:06 +0000 |
commit | a558fd42873865cc1e93a5916713f850c510d76e (patch) | |
tree | 4b2998e8222d758131a6b3f6b82324e81255caff | |
parent | ef5c7840b2f35bc1d07401510d60f458bcfc23cd (diff) | |
download | gcc-a558fd42873865cc1e93a5916713f850c510d76e.tar.gz |
2012-10-17 Benjamin Kosnik <bkoz@redhat.com>
* include/bits/move.h (move_if_noexcept): Mark constexpr.
* include/std/array (front, back): Same.
* include/std/chrono: Add comment.
* include/std/tuple (__tuple_compare): Mark __eq, __less constexpr.
(operator ==, <, >, !=, <=, >=): Same.
* testsuite/20_util/forward/c_neg.cc: Adjust line numbers.
* testsuite/20_util/forward/f_neg.cc: Same.
* testsuite/20_util/move_if_noexcept/constexpr.cc: New.
* testsuite/20_util/tuple/comparison_operators/constexpr.cc: New.
* testsuite/20_util/tuple/creation_functions/constexpr.cc: Add.
* testsuite/23_containers/array/element_access/
constexpr_element_access.cc: Same.
* testsuite/23_containers/array/tuple_interface/get_neg.cc: Adjust
line numbers.
* testsuite/23_containers/array/tuple_interface/tuple_element_neg.cc:
Same.
* testsuite/20_util/tuple/comparison_operators/35480_neg.cc:
Temporarily add dg-excess-errors.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@192556 138bc75d-0d04-0410-961f-82ee72b054a4
14 files changed, 177 insertions, 32 deletions
diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index 3527fbccc9d..709f47986c0 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,3 +1,25 @@ +2012-10-17 Benjamin Kosnik <bkoz@redhat.com> + + * include/bits/move.h (move_if_noexcept): Mark constexpr. + * include/std/array (front, back): Same. + * include/std/chrono: Add comment. + * include/std/tuple (__tuple_compare): Mark __eq, __less constexpr. + (operator ==, <, >, !=, <=, >=): Same. + * testsuite/20_util/forward/c_neg.cc: Adjust line numbers. + * testsuite/20_util/forward/f_neg.cc: Same. + * testsuite/20_util/move_if_noexcept/constexpr.cc: New. + * testsuite/20_util/tuple/comparison_operators/constexpr.cc: New. + * testsuite/20_util/tuple/creation_functions/constexpr.cc: Add. + * testsuite/23_containers/array/element_access/ + constexpr_element_access.cc: Same. + * testsuite/23_containers/array/tuple_interface/get_neg.cc: Adjust + line numbers. + * testsuite/23_containers/array/tuple_interface/tuple_element_neg.cc: + Same. + + * testsuite/20_util/tuple/comparison_operators/35480_neg.cc: + Temporarily add dg-excess-errors. + 2012-10-16 François Dumont <fdumont@gcc.gnu.org> * include/debug/formatter.h (_Debug_msg_id): Add diff --git a/libstdc++-v3/include/bits/move.h b/libstdc++-v3/include/bits/move.h index 353c466d8fc..236f0de300a 100644 --- a/libstdc++-v3/include/bits/move.h +++ b/libstdc++-v3/include/bits/move.h @@ -1,6 +1,6 @@ // Move, forward and identity for C++0x + swap -*- C++ -*- -// Copyright (C) 2007, 2008, 2009, 2010, 2011 Free Software Foundation, Inc. +// Copyright (C) 2007-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 @@ -65,7 +65,6 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION * @{ */ - // forward (as per N3143) /** * @brief Forward an lvalue. * @return The parameter cast to the specified type. @@ -117,7 +116,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION * type is copyable, in which case an lvalue-reference is returned instead. */ template<typename _Tp> - inline typename + inline constexpr typename conditional<__move_if_noexcept_cond<_Tp>::value, const _Tp&, _Tp&&>::type move_if_noexcept(_Tp& __x) noexcept { return std::move(__x); } diff --git a/libstdc++-v3/include/std/array b/libstdc++-v3/include/std/array index c7c0a5ae824..15dd6c13222 100644 --- a/libstdc++-v3/include/std/array +++ b/libstdc++-v3/include/std/array @@ -198,17 +198,20 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION front() { return *begin(); } - const_reference + constexpr const_reference front() const - { return *begin(); } + { return _AT_Type::_S_ref(_M_elems, 0); } reference back() { return _Nm ? *(end() - 1) : *end(); } - const_reference + constexpr const_reference back() const - { return _Nm ? *(end() - 1) : *end(); } + { + return _Nm ? _AT_Type::_S_ref(_M_elems, _Nm - 1) + : _AT_Type::_S_ref(_M_elems, _Nm); + } pointer data() noexcept diff --git a/libstdc++-v3/include/std/chrono b/libstdc++-v3/include/std/chrono index 209f395ed3d..d920a7dd379 100644 --- a/libstdc++-v3/include/std/chrono +++ b/libstdc++-v3/include/std/chrono @@ -250,7 +250,10 @@ _GLIBCXX_END_NAMESPACE_VERSION // 20.11.5.1 construction / copy / destroy constexpr duration() = default; - constexpr duration(const duration&) = default; + // NB: Make constexpr implicit. This cannot be explicitly + // constexpr, as any UDT that is not a literal type with a + // constexpr copy constructor will be ill-formed. + duration(const duration&) = default; template<typename _Rep2, typename = typename enable_if<is_convertible<_Rep2, rep>::value diff --git a/libstdc++-v3/include/std/tuple b/libstdc++-v3/include/std/tuple index fb9e09fffe8..b4985d280d8 100644 --- a/libstdc++-v3/include/std/tuple +++ b/libstdc++-v3/include/std/tuple @@ -775,14 +775,14 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION template<std::size_t __i, std::size_t __j, typename _Tp, typename _Up> struct __tuple_compare<0, __i, __j, _Tp, _Up> { - static bool + static constexpr bool __eq(const _Tp& __t, const _Up& __u) { return (get<__i>(__t) == get<__i>(__u) && __tuple_compare<0, __i + 1, __j, _Tp, _Up>::__eq(__t, __u)); } - static bool + static constexpr bool __less(const _Tp& __t, const _Up& __u) { return ((get<__i>(__t) < get<__i>(__u)) @@ -794,55 +794,55 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION template<std::size_t __i, typename _Tp, typename _Up> struct __tuple_compare<0, __i, __i, _Tp, _Up> { - static bool + static constexpr bool __eq(const _Tp&, const _Up&) { return true; } - static bool + static constexpr bool __less(const _Tp&, const _Up&) { return false; } }; template<typename... _TElements, typename... _UElements> - bool + constexpr bool operator==(const tuple<_TElements...>& __t, const tuple<_UElements...>& __u) { typedef tuple<_TElements...> _Tp; typedef tuple<_UElements...> _Up; - return (__tuple_compare<tuple_size<_Tp>::value - tuple_size<_Up>::value, + return bool(__tuple_compare<tuple_size<_Tp>::value - tuple_size<_Up>::value, 0, tuple_size<_Tp>::value, _Tp, _Up>::__eq(__t, __u)); } template<typename... _TElements, typename... _UElements> - bool + constexpr bool operator<(const tuple<_TElements...>& __t, const tuple<_UElements...>& __u) { typedef tuple<_TElements...> _Tp; typedef tuple<_UElements...> _Up; - return (__tuple_compare<tuple_size<_Tp>::value - tuple_size<_Up>::value, + return bool(__tuple_compare<tuple_size<_Tp>::value - tuple_size<_Up>::value, 0, tuple_size<_Tp>::value, _Tp, _Up>::__less(__t, __u)); } template<typename... _TElements, typename... _UElements> - inline bool + inline constexpr bool operator!=(const tuple<_TElements...>& __t, const tuple<_UElements...>& __u) { return !(__t == __u); } template<typename... _TElements, typename... _UElements> - inline bool + inline constexpr bool operator>(const tuple<_TElements...>& __t, const tuple<_UElements...>& __u) { return __u < __t; } template<typename... _TElements, typename... _UElements> - inline bool + inline constexpr bool operator<=(const tuple<_TElements...>& __t, const tuple<_UElements...>& __u) { return !(__u < __t); } template<typename... _TElements, typename... _UElements> - inline bool + inline constexpr bool operator>=(const tuple<_TElements...>& __t, const tuple<_UElements...>& __u) { return !(__t < __u); } @@ -858,7 +858,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION } template<typename... _Elements> - constexpr tuple<_Elements&&...> + tuple<_Elements&&...> forward_as_tuple(_Elements&&... __args) noexcept { return tuple<_Elements&&...>(std::forward<_Elements>(__args)...); } diff --git a/libstdc++-v3/testsuite/20_util/forward/c_neg.cc b/libstdc++-v3/testsuite/20_util/forward/c_neg.cc index 01128245d7e..1e573ec2757 100644 --- a/libstdc++-v3/testsuite/20_util/forward/c_neg.cc +++ b/libstdc++-v3/testsuite/20_util/forward/c_neg.cc @@ -1,7 +1,7 @@ // { dg-do compile } // { dg-options "-std=gnu++0x" } -// Copyright (C) 2010, 2011 Free Software Foundation, Inc. +// Copyright (C) 2010-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 @@ -18,7 +18,7 @@ // with this library; see the file COPYING3. If not see // <http://www.gnu.org/licenses/>. -// { dg-error "static assertion failed" "" { target *-*-* } 90 } +// { dg-error "static assertion failed" "" { target *-*-* } 89 } #include <list> diff --git a/libstdc++-v3/testsuite/20_util/forward/f_neg.cc b/libstdc++-v3/testsuite/20_util/forward/f_neg.cc index 9e5b78a04db..d4a9c7a2af6 100644 --- a/libstdc++-v3/testsuite/20_util/forward/f_neg.cc +++ b/libstdc++-v3/testsuite/20_util/forward/f_neg.cc @@ -1,7 +1,7 @@ // { dg-do compile } // { dg-options "-std=gnu++0x" } -// Copyright (C) 2010, 2011 Free Software Foundation, Inc. +// Copyright (C) 2010-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 @@ -18,7 +18,7 @@ // with this library; see the file COPYING3. If not see // <http://www.gnu.org/licenses/>. -// { dg-error "static assertion failed" "" { target *-*-* } 90 } +// { dg-error "static assertion failed" "" { target *-*-* } 89 } #include <utility> diff --git a/libstdc++-v3/testsuite/20_util/move_if_noexcept/constexpr.cc b/libstdc++-v3/testsuite/20_util/move_if_noexcept/constexpr.cc new file mode 100644 index 00000000000..4811b17cbd9 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/move_if_noexcept/constexpr.cc @@ -0,0 +1,42 @@ +// { dg-do compile } +// { dg-options "-std=gnu++0x" } + +// 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 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 +// <http://www.gnu.org/licenses/>. + +#include <utility> +#include <testsuite_hooks.h> + +struct simple +{ + int i; +}; + +void +test01() +{ + bool test __attribute__((unused)) = true; + + constexpr simple s { 5 }; + constexpr auto s2 __attribute__((unused)) = std::move_if_noexcept(s); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/20_util/tuple/comparison_operators/35480_neg.cc b/libstdc++-v3/testsuite/20_util/tuple/comparison_operators/35480_neg.cc index eb22938261a..eb4c213eddb 100644 --- a/libstdc++-v3/testsuite/20_util/tuple/comparison_operators/35480_neg.cc +++ b/libstdc++-v3/testsuite/20_util/tuple/comparison_operators/35480_neg.cc @@ -1,7 +1,7 @@ // { dg-options "-std=gnu++0x" } // { dg-do compile } -// Copyright (C) 2008, 2009 Free Software Foundation, Inc. +// Copyright (C) 2008, 2009, 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 @@ -31,3 +31,4 @@ void test01() if ( t1 == t2 ) {} // { dg-error "here" } } // { dg-prune-output "incomplete type" } +// { dg-excess-errors "body of constexpr function" } diff --git a/libstdc++-v3/testsuite/20_util/tuple/comparison_operators/constexpr.cc b/libstdc++-v3/testsuite/20_util/tuple/comparison_operators/constexpr.cc new file mode 100644 index 00000000000..0efb4c3da91 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/tuple/comparison_operators/constexpr.cc @@ -0,0 +1,29 @@ +// { dg-do compile } +// { dg-options "-std=gnu++0x" } + +// 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 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 +// <http://www.gnu.org/licenses/>. + +#include <tuple> +#include <testsuite_common_types.h> + +int main() +{ + __gnu_test::constexpr_comparison_operators test; + test.operator()<std::tuple<int, int>>(); + return 0; +} diff --git a/libstdc++-v3/testsuite/20_util/tuple/creation_functions/constexpr.cc b/libstdc++-v3/testsuite/20_util/tuple/creation_functions/constexpr.cc index bf2a8573abf..6c260605c05 100644 --- a/libstdc++-v3/testsuite/20_util/tuple/creation_functions/constexpr.cc +++ b/libstdc++-v3/testsuite/20_util/tuple/creation_functions/constexpr.cc @@ -1,7 +1,7 @@ // { dg-do compile } // { dg-options "-std=gnu++0x" } -// Copyright (C) 2011 Free Software Foundation, Inc. +// Copyright (C) 2011, 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 @@ -45,6 +45,50 @@ test_make_tuple() } } +#if 0 +// forward_as_tuple +void +test_forward_as_tuple() +{ + { + typedef std::tuple<int, float> tuple_type; + constexpr tuple_type p1 __attribute__((unused)) + = std::forward_as_tuple(22, 22.222); + } + + { + typedef std::tuple<int, float, int> tuple_type; + constexpr tuple_type p1 __attribute__((unused)) + = std::forward_as_tuple(22, 22.222, 77799); + } +} +#endif + +#if 0 +// tie +void +test_tie() +{ + { + int i(22); + float f(22.222); + typedef std::tuple<int, float> tuple_type; + constexpr tuple_type p1 __attribute__((unused)) + = std::tie(i, f); + } + + { + int i(22); + float f(22.222); + int ii(77799); + + typedef std::tuple<int, float, int> tuple_type; + constexpr tuple_type p1 __attribute__((unused)) + = std::tie(i, f, ii); + } +} +#endif + // get void test_get() diff --git a/libstdc++-v3/testsuite/23_containers/array/element_access/constexpr_element_access.cc b/libstdc++-v3/testsuite/23_containers/array/element_access/constexpr_element_access.cc index c2f301adcd4..ec46ac0d388 100644 --- a/libstdc++-v3/testsuite/23_containers/array/element_access/constexpr_element_access.cc +++ b/libstdc++-v3/testsuite/23_containers/array/element_access/constexpr_element_access.cc @@ -1,7 +1,7 @@ // { dg-do compile } // { dg-options "-std=gnu++0x" } -// Copyright (C) 2011 Free Software Foundation, Inc. +// Copyright (C) 2011-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 @@ -27,5 +27,7 @@ int main() constexpr array_type a = { { 0, 55, 66, 99, 4115, 2 } }; constexpr auto v1 __attribute__((unused)) = a[1]; constexpr auto v2 __attribute__((unused)) = a.at(2); + constexpr auto v3 __attribute__((unused)) = a.front(); + constexpr auto v4 __attribute__((unused)) = a.back(); return 0; } diff --git a/libstdc++-v3/testsuite/23_containers/array/tuple_interface/get_neg.cc b/libstdc++-v3/testsuite/23_containers/array/tuple_interface/get_neg.cc index e74af1b4f43..7c7a365cb4e 100644 --- a/libstdc++-v3/testsuite/23_containers/array/tuple_interface/get_neg.cc +++ b/libstdc++-v3/testsuite/23_containers/array/tuple_interface/get_neg.cc @@ -27,6 +27,6 @@ int n1 = std::get<1>(a); int n2 = std::get<1>(std::move(a)); int n3 = std::get<1>(ca); -// { dg-error "static assertion failed" "" { target *-*-* } 288 } -// { dg-error "static assertion failed" "" { target *-*-* } 296 } -// { dg-error "static assertion failed" "" { target *-*-* } 304 } +// { dg-error "static assertion failed" "" { target *-*-* } 291 } +// { dg-error "static assertion failed" "" { target *-*-* } 299 } +// { dg-error "static assertion failed" "" { target *-*-* } 307 } diff --git a/libstdc++-v3/testsuite/23_containers/array/tuple_interface/tuple_element_neg.cc b/libstdc++-v3/testsuite/23_containers/array/tuple_interface/tuple_element_neg.cc index b9ce910f61a..3c642c800b0 100644 --- a/libstdc++-v3/testsuite/23_containers/array/tuple_interface/tuple_element_neg.cc +++ b/libstdc++-v3/testsuite/23_containers/array/tuple_interface/tuple_element_neg.cc @@ -22,4 +22,4 @@ typedef std::tuple_element<1, std::array<int, 1>>::type type; -// { dg-error "static assertion failed" "" { target *-*-* } 280 } +// { dg-error "static assertion failed" "" { target *-*-* } 283 } |