diff mbox series

[committed] libstdc++: Add test for chrono::leap_seconds ostream insertion

Message ID 20240611120725.682088-1-jwakely@redhat.com
State New
Headers show
Series [committed] libstdc++: Add test for chrono::leap_seconds ostream insertion | expand

Commit Message

Jonathan Wakely June 11, 2024, 12:07 p.m. UTC
Tested x86_64-linux. Pushed to trunk.

-- >8 --

Also add a comment to the three-way comparison oeprator for
chrono::leap_seconds, noting the deviation from the spec (which is
functionally equivalent). What we implement is the originally proposed
resolution to LWG 3383, which should compile slightly more efficiently
than the final accepted resolution.

libstdc++-v3/ChangeLog:

	* include/std/chrono (leap_seconds): Add comment.
	* testsuite/std/time/leap_seconds/io.cc: New test.
---
 libstdc++-v3/include/std/chrono               |  2 +
 .../testsuite/std/time/leap_seconds/io.cc     | 56 +++++++++++++++++++
 2 files changed, 58 insertions(+)
 create mode 100644 libstdc++-v3/testsuite/std/time/leap_seconds/io.cc
diff mbox series

Patch

diff --git a/libstdc++-v3/include/std/chrono b/libstdc++-v3/include/std/chrono
index b0aadf83b03..7ffa5360728 100644
--- a/libstdc++-v3/include/std/chrono
+++ b/libstdc++-v3/include/std/chrono
@@ -2925,6 +2925,8 @@  _GLIBCXX_BEGIN_NAMESPACE_VERSION
 		   const leap_second& __y) noexcept
 	{ return !(__x < __y.date()); }
 
+      // This is a simplified form of the constraint specified in the standard,
+      // three_way_comparable_with<sys_seconds, sys_time<_Duration>>.
       template<three_way_comparable_with<seconds> _Duration>
 	[[nodiscard]] friend constexpr auto
 	operator<=>(const leap_second& __x,
diff --git a/libstdc++-v3/testsuite/std/time/leap_seconds/io.cc b/libstdc++-v3/testsuite/std/time/leap_seconds/io.cc
new file mode 100644
index 00000000000..511fafdd1a0
--- /dev/null
+++ b/libstdc++-v3/testsuite/std/time/leap_seconds/io.cc
@@ -0,0 +1,56 @@ 
+// { dg-do run { target c++20 } }
+// { dg-require-effective-target tzdb }
+// { dg-require-effective-target cxx11_abi }
+
+#include <chrono>
+#include <sstream>
+#include <format>
+#include <testsuite_hooks.h>
+
+void
+test_output()
+{
+  using namespace std::chrono;
+
+  std::ostringstream out;
+  out << '\n';
+
+  for (auto& l : get_tzdb().leap_seconds)
+  if (l <= sys_days{2018y/March/17d})
+    out << l.date() << ": " << l.value() << '\n';
+
+  VERIFY( out.str() == R"(
+1972-07-01 00:00:00: 1s
+1973-01-01 00:00:00: 1s
+1974-01-01 00:00:00: 1s
+1975-01-01 00:00:00: 1s
+1976-01-01 00:00:00: 1s
+1977-01-01 00:00:00: 1s
+1978-01-01 00:00:00: 1s
+1979-01-01 00:00:00: 1s
+1980-01-01 00:00:00: 1s
+1981-07-01 00:00:00: 1s
+1982-07-01 00:00:00: 1s
+1983-07-01 00:00:00: 1s
+1985-07-01 00:00:00: 1s
+1988-01-01 00:00:00: 1s
+1990-01-01 00:00:00: 1s
+1991-01-01 00:00:00: 1s
+1992-07-01 00:00:00: 1s
+1993-07-01 00:00:00: 1s
+1994-07-01 00:00:00: 1s
+1996-01-01 00:00:00: 1s
+1997-07-01 00:00:00: 1s
+1999-01-01 00:00:00: 1s
+2006-01-01 00:00:00: 1s
+2009-01-01 00:00:00: 1s
+2012-07-01 00:00:00: 1s
+2015-07-01 00:00:00: 1s
+2017-01-01 00:00:00: 1s
+)" );
+}
+
+int main()
+{
+  test_output();
+}