public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] P0972R0 <chrono> zero(), min(), and max() should be noexcept
@ 2019-01-11 23:41 Jonathan Wakely
  0 siblings, 0 replies; only message in thread
From: Jonathan Wakely @ 2019-01-11 23:41 UTC (permalink / raw)
  To: libstdc++, gcc-patches

[-- Attachment #1: Type: text/plain, Size: 566 bytes --]

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.

Tested powerpc64le-linux, committed to trunk.


[-- Attachment #2: patch.txt --]
[-- Type: text/plain, Size: 6033 bytes --]

commit 98c18da3d74259e038a39c77e3d04494f9395dff
Author: Jonathan Wakely <jwakely@redhat.com>
Date:   Fri Jan 11 22:45:27 2019 +0000

    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.

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

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2019-01-11 23:41 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-01-11 23:41 [PATCH] P0972R0 <chrono> zero(), min(), and max() should be noexcept Jonathan Wakely

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).