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
This commit is contained in:
Jonathan Wakely 2019-01-11 23:41:05 +00:00 committed by Jonathan Wakely
parent 89508a3fc6
commit 5e9aed14dc
4 changed files with 99 additions and 8 deletions

View File

@ -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>

View File

@ -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:

View File

@ -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()" );

View File

@ -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()" );