From a9ba8ba56c16e80fd9134822bdfe34f565f4ccf4 Mon Sep 17 00:00:00 2001 From: Benjamin Kosnik Date: Thu, 18 Oct 2012 08:36:06 +0000 Subject: [PATCH] move.h (move_if_noexcept): Mark constexpr. 2012-10-17 Benjamin Kosnik * 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. From-SVN: r192556 --- libstdc++-v3/ChangeLog | 22 +++++++++ libstdc++-v3/include/bits/move.h | 5 +- libstdc++-v3/include/std/array | 11 +++-- libstdc++-v3/include/std/chrono | 5 +- libstdc++-v3/include/std/tuple | 26 +++++------ .../testsuite/20_util/forward/c_neg.cc | 4 +- .../testsuite/20_util/forward/f_neg.cc | 4 +- .../20_util/move_if_noexcept/constexpr.cc | 42 +++++++++++++++++ .../tuple/comparison_operators/35480_neg.cc | 3 +- .../tuple/comparison_operators/constexpr.cc | 29 ++++++++++++ .../tuple/creation_functions/constexpr.cc | 46 ++++++++++++++++++- .../constexpr_element_access.cc | 4 +- .../array/tuple_interface/get_neg.cc | 6 +-- .../tuple_interface/tuple_element_neg.cc | 2 +- 14 files changed, 177 insertions(+), 32 deletions(-) create mode 100644 libstdc++-v3/testsuite/20_util/move_if_noexcept/constexpr.cc create mode 100644 libstdc++-v3/testsuite/20_util/tuple/comparison_operators/constexpr.cc 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 + + * 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 * 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 - 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::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 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 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 - bool + constexpr bool operator==(const tuple<_TElements...>& __t, const tuple<_UElements...>& __u) { typedef tuple<_TElements...> _Tp; typedef tuple<_UElements...> _Up; - return (__tuple_compare::value - tuple_size<_Up>::value, + return bool(__tuple_compare::value - tuple_size<_Up>::value, 0, tuple_size<_Tp>::value, _Tp, _Up>::__eq(__t, __u)); } template - bool + constexpr bool operator<(const tuple<_TElements...>& __t, const tuple<_UElements...>& __u) { typedef tuple<_TElements...> _Tp; typedef tuple<_UElements...> _Up; - return (__tuple_compare::value - tuple_size<_Up>::value, + return bool(__tuple_compare::value - tuple_size<_Up>::value, 0, tuple_size<_Tp>::value, _Tp, _Up>::__less(__t, __u)); } template - inline bool + inline constexpr bool operator!=(const tuple<_TElements...>& __t, const tuple<_UElements...>& __u) { return !(__t == __u); } template - inline bool + inline constexpr bool operator>(const tuple<_TElements...>& __t, const tuple<_UElements...>& __u) { return __u < __t; } template - inline bool + inline constexpr bool operator<=(const tuple<_TElements...>& __t, const tuple<_UElements...>& __u) { return !(__u < __t); } template - 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 - 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 // . -// { dg-error "static assertion failed" "" { target *-*-* } 90 } +// { dg-error "static assertion failed" "" { target *-*-* } 89 } #include 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 // . -// { dg-error "static assertion failed" "" { target *-*-* } 90 } +// { dg-error "static assertion failed" "" { target *-*-* } 89 } #include 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 +// . + +#include +#include + +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 +// . + +#include +#include + +int main() +{ + __gnu_test::constexpr_comparison_operators test; + test.operator()>(); + 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 tuple_type; + constexpr tuple_type p1 __attribute__((unused)) + = std::forward_as_tuple(22, 22.222); + } + + { + typedef std::tuple 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 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 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>::type type; -// { dg-error "static assertion failed" "" { target *-*-* } 280 } +// { dg-error "static assertion failed" "" { target *-*-* } 283 } -- 2.30.2