From: Jonathan Wakely Date: Fri, 11 Jan 2019 23:41:05 +0000 (+0000) Subject: P0972R0 zero(), min(), and max() should be noexcept X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=5e9aed14dcb5c984186f8b1e042bde9f3aaafa5e;p=gcc.git P0972R0 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 --- diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index 8bf6884c850..1a0211336b3 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,5 +1,12 @@ 2019-01-11 Jonathan Wakely + * 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 diff --git a/libstdc++-v3/include/std/chrono b/libstdc++-v3/include/std/chrono index 3ac0860df5e..9e63fa9c698 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::zero()); } static constexpr duration - min() + min() noexcept { return duration(duration_values::min()); } static constexpr duration - max() + max() noexcept { return duration(duration_values::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 00000000000..03bad272ff4 --- /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 +// . + +// { dg-do compile { target c++11 } } + +// P0972R0 zero(), min(), and max() should be noexcept + +#include + +using namespace std; + +using vals = chrono::duration_values; +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>; +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 00000000000..075cbbc6fee --- /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 +// . + +// { dg-do compile { target c++11 } } + +// P0972R0 zero(), min(), and max() should be noexcept + +#include + +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; + using time_point = chrono::time_point; + 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>>; +static_assert( noexcept(tp3::min()), "time_point::min()" ); +static_assert( noexcept(tp3::max()), "time_point::max()" );