diff options
author | Jonathan Wakely <jwakely@redhat.com> | 2019-01-11 23:41:05 +0000 |
---|---|---|
committer | Jonathan Wakely <redi@gcc.gnu.org> | 2019-01-11 23:41:05 +0000 |
commit | 5e9aed14dcb5c984186f8b1e042bde9f3aaafa5e (patch) | |
tree | 61967e9e3bcec9ac2316154f7963b57bd7093a4f /libstdc++-v3 | |
parent | 89508a3fc645ef37340e31c74995c3078e1b1b9b (diff) | |
download | gcc-5e9aed14dcb5c984186f8b1e042bde9f3aaafa5e.zip gcc-5e9aed14dcb5c984186f8b1e042bde9f3aaafa5e.tar.gz gcc-5e9aed14dcb5c984186f8b1e042bde9f3aaafa5e.tar.bz2 |
P0972R0 <chrono> zero(), min(), and max() should be noexcept
This paper has been included in the C++20 draft, but the changes to add
noexcept can be made unconditionally, to apply for C++11 too.
* include/std/chrono (duration_values::zero(), duration_values::min())
(duration_values::max()): Add noexcept.
(duration::zero(), duration::min(), duration::max()): Likewise.
(time_point::zero(), time_point::min(), time_point::max()): Likewise.
* testsuite/20_util/duration/requirements/noexcept.cc: New test.
* testsuite/20_util/time_point/requirements/noexcept.cc: New test.
From-SVN: r267865
Diffstat (limited to 'libstdc++-v3')
-rw-r--r-- | libstdc++-v3/ChangeLog | 7 | ||||
-rw-r--r-- | libstdc++-v3/include/std/chrono | 16 | ||||
-rw-r--r-- | libstdc++-v3/testsuite/20_util/duration/requirements/noexcept.cc | 39 | ||||
-rw-r--r-- | libstdc++-v3/testsuite/20_util/time_point/requirements/noexcept.cc | 45 |
4 files changed, 99 insertions, 8 deletions
diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index 8bf6884..1a02113 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,5 +1,12 @@ 2019-01-11 Jonathan Wakely <jwakely@redhat.com> + * include/std/chrono (duration_values::zero(), duration_values::min()) + (duration_values::max()): Add noexcept. + (duration::zero(), duration::min(), duration::max()): Likewise. + (time_point::zero(), time_point::min(), time_point::max()): Likewise. + * testsuite/20_util/duration/requirements/noexcept.cc: New test. + * testsuite/20_util/time_point/requirements/noexcept.cc: New test. + * include/std/version (__cpp_lib_erase_if): Move to C++20 group. 2019-01-11 Jakub Jelinek <jakub@redhat.com> diff --git a/libstdc++-v3/include/std/chrono b/libstdc++-v3/include/std/chrono index 3ac0860..9e63fa9 100644 --- a/libstdc++-v3/include/std/chrono +++ b/libstdc++-v3/include/std/chrono @@ -273,15 +273,15 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION struct duration_values { static constexpr _Rep - zero() + zero() noexcept { return _Rep(0); } static constexpr _Rep - max() + max() noexcept { return numeric_limits<_Rep>::max(); } static constexpr _Rep - min() + min() noexcept { return numeric_limits<_Rep>::lowest(); } }; @@ -428,15 +428,15 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION // 20.11.5.4 special values static constexpr duration - zero() + zero() noexcept { return duration(duration_values<rep>::zero()); } static constexpr duration - min() + min() noexcept { return duration(duration_values<rep>::min()); } static constexpr duration - max() + max() noexcept { return duration(duration_values<rep>::max()); } private: @@ -666,11 +666,11 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION // special values static constexpr time_point - min() + min() noexcept { return time_point(duration::min()); } static constexpr time_point - max() + max() noexcept { return time_point(duration::max()); } private: diff --git a/libstdc++-v3/testsuite/20_util/duration/requirements/noexcept.cc b/libstdc++-v3/testsuite/20_util/duration/requirements/noexcept.cc new file mode 100644 index 0000000..03bad27 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/duration/requirements/noexcept.cc @@ -0,0 +1,39 @@ +// Copyright (C) 2019 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/>. + +// { dg-do compile { target c++11 } } + +// P0972R0 <chrono> zero(), min(), and max() should be noexcept + +#include <chrono> + +using namespace std; + +using vals = chrono::duration_values<short>; +static_assert( noexcept(vals::zero()), "duration_values::zero()" ); +static_assert( noexcept(vals::min()), "duration_values::min()" ); +static_assert( noexcept(vals::max()), "duration_values::max()" ); + +using dur1 = chrono::system_clock::duration; +static_assert( noexcept(dur1::zero()), "duration::zero()" ); +static_assert( noexcept(dur1::min()), "duration::min()" ); +static_assert( noexcept(dur1::max()), "duration::max()" ); + +using dur2 = chrono::duration<short, ratio<10>>; +static_assert( noexcept(dur2::zero()), "duration::zero()" ); +static_assert( noexcept(dur2::min()), "duration::min()" ); +static_assert( noexcept(dur2::max()), "duration::max()" ); diff --git a/libstdc++-v3/testsuite/20_util/time_point/requirements/noexcept.cc b/libstdc++-v3/testsuite/20_util/time_point/requirements/noexcept.cc new file mode 100644 index 0000000..075cbbc --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/time_point/requirements/noexcept.cc @@ -0,0 +1,45 @@ +// Copyright (C) 2019 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/>. + +// { dg-do compile { target c++11 } } + +// P0972R0 <chrono> zero(), min(), and max() should be noexcept + +#include <chrono> + +using namespace std; + +using tp1 = chrono::system_clock::time_point; +static_assert( noexcept(tp1::min()), "time_point::min()" ); +static_assert( noexcept(tp1::max()), "time_point::max()" ); + +struct Clock { + using rep = int; + using period = ratio<1, 24>; + using duration = chrono::duration<rep, period>; + using time_point = chrono::time_point<Clock>; + static constexpr bool is_steady = false; + static time_point now() noexcept; +}; + +using tp2 = Clock::time_point; +static_assert( noexcept(tp2::min()), "time_point::min()" ); +static_assert( noexcept(tp2::max()), "time_point::max()" ); + +using tp3 = chrono::time_point<Clock, chrono::duration<long, ratio<10>>>; +static_assert( noexcept(tp3::min()), "time_point::min()" ); +static_assert( noexcept(tp3::max()), "time_point::max()" ); |