[llvm-branch-commits] [libcxx] [libc++][chrono] Loads leap-seconds.list in tzdb. (PR #82113)

2024-02-17 Thread Mark de Wever via llvm-branch-commits

https://github.com/mordante created 
https://github.com/llvm/llvm-project/pull/82113

This implements the loading of the leap-seconds.list file and store its 
contents in the tzdb struct.

This adds the required `leap_seconds` member.

The class leap_seconds is fully implemented including its non-member functions.

Implements parts of:
- P0355 Extending  to Calendars and Time Zones
- P1614 The Mothership has Landed

Implements:
- P1981 Rename leap to leap_second
- LWG3359  leap second support should allow for negative leap seconds
- LWG3383 §[time.zone.leap.nonmembers] sys_seconds should be replaced with 
seconds

>From 3c588bde050451bc8cf3a934b101585b8519abd5 Mon Sep 17 00:00:00 2001
From: Mark de Wever 
Date: Fri, 23 Sep 2022 18:33:20 +0200
Subject: [PATCH] [libc++][chrono] Loads leap-seconds.list in tzdb.
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

This implements the loading of the leap-seconds.list file and store its
contents in the tzdb struct.

This adds the required `leap_seconds` member.

The class leap_seconds is fully implemented including its non-member
functions.

Implements parts of:
- P0355 Extending  to Calendars and Time Zones
- P1614 The Mothership has Landed

Implements:
- P1981 Rename leap to leap_second
- LWG3359  leap second support should allow for negative leap seconds
- LWG3383 §[time.zone.leap.nonmembers] sys_seconds should be replaced with 
seconds
---
 libcxx/docs/Status/Cxx20Issues.csv|   4 +-
 libcxx/docs/Status/Cxx20Papers.csv|   2 +-
 libcxx/docs/Status/SpaceshipProjects.csv  |   2 +-
 libcxx/include/CMakeLists.txt |   1 +
 libcxx/include/__chrono/leap_second.h | 112 ++
 libcxx/include/__chrono/tzdb.h|   3 +
 libcxx/include/chrono |  39 ++
 libcxx/include/libcxx.imp |   1 +
 libcxx/include/module.modulemap.in|   1 +
 libcxx/modules/std/chrono.inc |  28 ++---
 libcxx/src/CMakeLists.txt |   1 +
 libcxx/src/include/tzdb/leap_second_private.h |  27 +
 libcxx/src/tzdb.cpp   |  41 +++
 ...rono.nodiscard_extensions.compile.pass.cpp |   6 +
 .../chrono.nodiscard_extensions.verify.cpp|   6 +
 .../time.zone.db/leap_seconds.pass.cpp| 102 
 .../time.zone.db.access/get_tzdb.pass.cpp |   3 +
 .../time.zone.leap/assign.copy.pass.cpp   |  56 +
 .../time.zone.leap/cons.copy.pass.cpp |  51 
 .../time.zone.leap/members/date.pass.cpp  |  48 
 .../time.zone.leap/members/value.pass.cpp |  48 
 .../nonmembers/comparison.pass.cpp|  77 
 libcxx/test/support/test_chrono_leap_second.h |  53 +
 23 files changed, 693 insertions(+), 19 deletions(-)
 create mode 100644 libcxx/include/__chrono/leap_second.h
 create mode 100644 libcxx/src/include/tzdb/leap_second_private.h
 create mode 100644 
libcxx/test/libcxx/time/time.zone/time.zone.db/leap_seconds.pass.cpp
 create mode 100644 
libcxx/test/std/time/time.zone/time.zone.leap/assign.copy.pass.cpp
 create mode 100644 
libcxx/test/std/time/time.zone/time.zone.leap/cons.copy.pass.cpp
 create mode 100644 
libcxx/test/std/time/time.zone/time.zone.leap/members/date.pass.cpp
 create mode 100644 
libcxx/test/std/time/time.zone/time.zone.leap/members/value.pass.cpp
 create mode 100644 
libcxx/test/std/time/time.zone/time.zone.leap/nonmembers/comparison.pass.cpp
 create mode 100644 libcxx/test/support/test_chrono_leap_second.h

diff --git a/libcxx/docs/Status/Cxx20Issues.csv 
b/libcxx/docs/Status/Cxx20Issues.csv
index f0e9c4090f9cf6..db57b15256a62f 100644
--- a/libcxx/docs/Status/Cxx20Issues.csv
+++ b/libcxx/docs/Status/Cxx20Issues.csv
@@ -269,7 +269,7 @@
 "`3355 `__","The memory algorithms should support 
move-only input iterators introduced by 
P1207","Prague","|Complete|","15.0","|ranges|"
 "`3356 `__","``__cpp_lib_nothrow_convertible``\  
should be ``__cpp_lib_is_nothrow_convertible``\ ","Prague","|Complete|","12.0"
 "`3358 `__","|sect|\ [span.cons] is mistaken that 
``to_address``\  can throw","Prague","|Complete|","17.0"
-"`3359 `__","\  leap second support 
should allow for negative leap seconds","Prague","","","|chrono|"
+"`3359 `__","\  leap second support 
should allow for negative leap seconds","Prague","|Complete|","19.0","|chrono|"
 "`3360 `__","``three_way_comparable_with``\  is 
inconsistent with similar concepts","Prague","|Nothing To Do|","","|spaceship|"
 "`3362 `__","Strike ``stop_source``\ 's 
``operator!=``\ ","Prague","",""
 "`3363 `__","``drop_while_view``\  should opt-out 
of ``sized_range``\ ","Prague","|Nothing To Do|","","|ranges|"
@@ -286,7 +286,7 @@

[llvm-branch-commits] [libcxx] [libc++][chrono] Loads leap-seconds.list in tzdb. (PR #82113)

2024-02-17 Thread via llvm-branch-commits

llvmbot wrote:




@llvm/pr-subscribers-libcxx

Author: Mark de Wever (mordante)


Changes

This implements the loading of the leap-seconds.list file and store its 
contents in the tzdb struct.

This adds the required `leap_seconds` member.

The class leap_seconds is fully implemented including its non-member functions.

Implements parts of:
- P0355 Extending  to Calendars and Time Zones
- P1614 The Mothership has Landed

Implements:
- P1981 Rename leap to leap_second
- LWG3359  leap second support should allow for negative leap 
seconds
- LWG3383 §[time.zone.leap.nonmembers] sys_seconds should be replaced with 
seconds

---

Patch is 39.88 KiB, truncated to 20.00 KiB below, full version: 
https://github.com/llvm/llvm-project/pull/82113.diff


23 Files Affected:

- (modified) libcxx/docs/Status/Cxx20Issues.csv (+2-2) 
- (modified) libcxx/docs/Status/Cxx20Papers.csv (+1-1) 
- (modified) libcxx/docs/Status/SpaceshipProjects.csv (+1-1) 
- (modified) libcxx/include/CMakeLists.txt (+1) 
- (added) libcxx/include/__chrono/leap_second.h (+112) 
- (modified) libcxx/include/__chrono/tzdb.h (+3) 
- (modified) libcxx/include/chrono (+39) 
- (modified) libcxx/include/libcxx.imp (+1) 
- (modified) libcxx/include/module.modulemap.in (+1) 
- (modified) libcxx/modules/std/chrono.inc (+13-15) 
- (modified) libcxx/src/CMakeLists.txt (+1) 
- (added) libcxx/src/include/tzdb/leap_second_private.h (+27) 
- (modified) libcxx/src/tzdb.cpp (+41) 
- (modified) 
libcxx/test/libcxx/diagnostics/chrono.nodiscard_extensions.compile.pass.cpp 
(+6) 
- (modified) 
libcxx/test/libcxx/diagnostics/chrono.nodiscard_extensions.verify.cpp (+6) 
- (added) libcxx/test/libcxx/time/time.zone/time.zone.db/leap_seconds.pass.cpp 
(+102) 
- (modified) 
libcxx/test/std/time/time.zone/time.zone.db/time.zone.db.access/get_tzdb.pass.cpp
 (+3) 
- (added) libcxx/test/std/time/time.zone/time.zone.leap/assign.copy.pass.cpp 
(+56) 
- (added) libcxx/test/std/time/time.zone/time.zone.leap/cons.copy.pass.cpp 
(+51) 
- (added) libcxx/test/std/time/time.zone/time.zone.leap/members/date.pass.cpp 
(+48) 
- (added) libcxx/test/std/time/time.zone/time.zone.leap/members/value.pass.cpp 
(+48) 
- (added) 
libcxx/test/std/time/time.zone/time.zone.leap/nonmembers/comparison.pass.cpp 
(+77) 
- (added) libcxx/test/support/test_chrono_leap_second.h (+53) 


``diff
diff --git a/libcxx/docs/Status/Cxx20Issues.csv 
b/libcxx/docs/Status/Cxx20Issues.csv
index f0e9c4090f9cf6..db57b15256a62f 100644
--- a/libcxx/docs/Status/Cxx20Issues.csv
+++ b/libcxx/docs/Status/Cxx20Issues.csv
@@ -269,7 +269,7 @@
 "`3355 `__","The memory algorithms should support 
move-only input iterators introduced by 
P1207","Prague","|Complete|","15.0","|ranges|"
 "`3356 `__","``__cpp_lib_nothrow_convertible``\  
should be ``__cpp_lib_is_nothrow_convertible``\ ","Prague","|Complete|","12.0"
 "`3358 `__","|sect|\ [span.cons] is mistaken that 
``to_address``\  can throw","Prague","|Complete|","17.0"
-"`3359 `__","\  leap second support 
should allow for negative leap seconds","Prague","","","|chrono|"
+"`3359 `__","\  leap second support 
should allow for negative leap seconds","Prague","|Complete|","19.0","|chrono|"
 "`3360 `__","``three_way_comparable_with``\  is 
inconsistent with similar concepts","Prague","|Nothing To Do|","","|spaceship|"
 "`3362 `__","Strike ``stop_source``\ 's 
``operator!=``\ ","Prague","",""
 "`3363 `__","``drop_while_view``\  should opt-out 
of ``sized_range``\ ","Prague","|Nothing To Do|","","|ranges|"
@@ -286,7 +286,7 @@
 "`3380 `__","``common_type``\  and comparison 
categories","Prague","|Complete|","15.0","|spaceship|"
 "`3381 `__","``begin``\  and ``data``\  must agree 
for ``contiguous_range``\ ","Prague","|Nothing To Do|","","|ranges|"
 "`3382 `__","NTTP for ``pair``\  and ``array``\ 
","Prague","",""
-"`3383 `__","|sect|\ [time.zone.leap.nonmembers] 
``sys_seconds``\  should be replaced with ``seconds``\ 
","Prague","","","|chrono|"
+"`3383 `__","|sect|\ [time.zone.leap.nonmembers] 
``sys_seconds``\  should be replaced with ``seconds``\ 
","Prague","|Complete|","19.0","|chrono|"
 "`3384 `__","``transform_view::*sentinel*``\  has 
an incorrect ``operator-``\ ","Prague","|Complete|","15.0","|ranges|"
 "`3385 `__","``common_iterator``\  is not 
sufficiently constrained for non-copyable 
iterators","Prague","|Complete|","15.0","|ranges|"
 "`3387 `__","|sect|\ [range.reverse.view] 
``reverse_view``\  unintentionally requires ``range``\ 
","Prague","|Complete|","15.0","|ranges|"
diff --git a/libcxx/docs/Status/Cxx20Papers.csv 
b/

[llvm-branch-commits] [libcxx] [libc++][chrono] Loads leap-seconds.list in tzdb. (PR #82113)

2024-02-17 Thread Mark de Wever via llvm-branch-commits

https://github.com/mordante updated 
https://github.com/llvm/llvm-project/pull/82113

>From 3710cf0f9e8fa6065b25123e9b2158079e10805c Mon Sep 17 00:00:00 2001
From: Mark de Wever 
Date: Fri, 23 Sep 2022 18:33:20 +0200
Subject: [PATCH] [libc++][chrono] Loads leap-seconds.list in tzdb.
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

This implements the loading of the leap-seconds.list file and store its
contents in the tzdb struct.

This adds the required `leap_seconds` member.

The class leap_seconds is fully implemented including its non-member
functions.

Implements parts of:
- P0355 Extending  to Calendars and Time Zones
- P1614 The Mothership has Landed

Implements:
- P1981 Rename leap to leap_second
- LWG3359  leap second support should allow for negative leap seconds
- LWG3383 §[time.zone.leap.nonmembers] sys_seconds should be replaced with 
seconds
---
 libcxx/docs/Status/Cxx20Issues.csv|   4 +-
 libcxx/docs/Status/Cxx20Papers.csv|   2 +-
 libcxx/docs/Status/SpaceshipProjects.csv  |   2 +-
 libcxx/include/CMakeLists.txt |   1 +
 libcxx/include/__chrono/leap_second.h | 112 ++
 libcxx/include/__chrono/tzdb.h|   3 +
 libcxx/include/chrono |  39 ++
 libcxx/include/libcxx.imp |   1 +
 libcxx/include/module.modulemap.in|   1 +
 libcxx/modules/std/chrono.inc |  28 ++---
 libcxx/src/CMakeLists.txt |   1 +
 libcxx/src/include/tzdb/leap_second_private.h |  27 +
 libcxx/src/tzdb.cpp   |  41 +++
 ...rono.nodiscard_extensions.compile.pass.cpp |   6 +
 .../chrono.nodiscard_extensions.verify.cpp|   6 +
 .../time.zone.db/leap_seconds.pass.cpp| 102 
 .../time.zone.db.access/get_tzdb.pass.cpp |   3 +
 .../time.zone.leap/assign.copy.pass.cpp   |  56 +
 .../time.zone.leap/cons.copy.pass.cpp |  51 
 .../time.zone.leap/members/date.pass.cpp  |  48 
 .../time.zone.leap/members/value.pass.cpp |  48 
 .../nonmembers/comparison.pass.cpp|  77 
 libcxx/test/support/test_chrono_leap_second.h |  53 +
 23 files changed, 693 insertions(+), 19 deletions(-)
 create mode 100644 libcxx/include/__chrono/leap_second.h
 create mode 100644 libcxx/src/include/tzdb/leap_second_private.h
 create mode 100644 
libcxx/test/libcxx/time/time.zone/time.zone.db/leap_seconds.pass.cpp
 create mode 100644 
libcxx/test/std/time/time.zone/time.zone.leap/assign.copy.pass.cpp
 create mode 100644 
libcxx/test/std/time/time.zone/time.zone.leap/cons.copy.pass.cpp
 create mode 100644 
libcxx/test/std/time/time.zone/time.zone.leap/members/date.pass.cpp
 create mode 100644 
libcxx/test/std/time/time.zone/time.zone.leap/members/value.pass.cpp
 create mode 100644 
libcxx/test/std/time/time.zone/time.zone.leap/nonmembers/comparison.pass.cpp
 create mode 100644 libcxx/test/support/test_chrono_leap_second.h

diff --git a/libcxx/docs/Status/Cxx20Issues.csv 
b/libcxx/docs/Status/Cxx20Issues.csv
index f0e9c4090f9cf6..db57b15256a62f 100644
--- a/libcxx/docs/Status/Cxx20Issues.csv
+++ b/libcxx/docs/Status/Cxx20Issues.csv
@@ -269,7 +269,7 @@
 "`3355 `__","The memory algorithms should support 
move-only input iterators introduced by 
P1207","Prague","|Complete|","15.0","|ranges|"
 "`3356 `__","``__cpp_lib_nothrow_convertible``\  
should be ``__cpp_lib_is_nothrow_convertible``\ ","Prague","|Complete|","12.0"
 "`3358 `__","|sect|\ [span.cons] is mistaken that 
``to_address``\  can throw","Prague","|Complete|","17.0"
-"`3359 `__","\  leap second support 
should allow for negative leap seconds","Prague","","","|chrono|"
+"`3359 `__","\  leap second support 
should allow for negative leap seconds","Prague","|Complete|","19.0","|chrono|"
 "`3360 `__","``three_way_comparable_with``\  is 
inconsistent with similar concepts","Prague","|Nothing To Do|","","|spaceship|"
 "`3362 `__","Strike ``stop_source``\ 's 
``operator!=``\ ","Prague","",""
 "`3363 `__","``drop_while_view``\  should opt-out 
of ``sized_range``\ ","Prague","|Nothing To Do|","","|ranges|"
@@ -286,7 +286,7 @@
 "`3380 `__","``common_type``\  and comparison 
categories","Prague","|Complete|","15.0","|spaceship|"
 "`3381 `__","``begin``\  and ``data``\  must agree 
for ``contiguous_range``\ ","Prague","|Nothing To Do|","","|ranges|"
 "`3382 `__","NTTP for ``pair``\  and ``array``\ 
","Prague","",""
-"`3383 `__","|sect|\ [time.zone.leap.nonmembers] 
``sys_seconds``\  should be replaced with ``seconds``\ 
","Prague","","","|chrono|"

[llvm-branch-commits] [libcxx] [libc++][chrono] Loads leap-seconds.list in tzdb. (PR #82113)

2024-02-27 Thread Louis Dionne via llvm-branch-commits

https://github.com/ldionne edited 
https://github.com/llvm/llvm-project/pull/82113
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [libcxx] [libc++][chrono] Loads leap-seconds.list in tzdb. (PR #82113)

2024-02-27 Thread Louis Dionne via llvm-branch-commits


@@ -0,0 +1,53 @@
+// -*- C++ -*-
+//===--===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#ifndef SUPPORT_TEST_CHRONO_LEAP_SECOND_HPP
+#define SUPPORT_TEST_CHRONO_LEAP_SECOND_HPP
+
+/**
+ * @file Helper functions to create a @ref std::chrono::leap_second.
+ *
+ * Since the standard doesn't specify how a @ref std::chrono::leap_second is
+ * constructed this is implementation defined. To make the public API tests of
+ * the class generic this header defines helper functions to create the
+ * required object.
+ *
+ * @note This requires every standard library implementation to write their own
+ * helper function. Vendors are encouraged to create a pull request at
+ * https://github.com/llvm/llvm-project so their specific implementation can be
+ * part of this file.
+ */
+
+#include "test_macros.h"
+
+#if TEST_STD_VER < 20
+#  error "The format header requires at least C++20"
+#endif
+
+#include 
+
+#ifdef _LIBCPP_VERSION
+
+// In order to find this include the calling test needs to provide this path in
+// the search path. Typically this looks like:
+//   REMOVE_THIS_PREFIX__ADDITIONAL_COMPILE_FLAGS(stdlib=libc++): -I 
%S/../../../../../../src/include
+// where the number of `../` sequences depends on the subdirectory level of the
+// test.
+#  include "tzdb/leap_second_private.h" // Header in the dylib
+
+inline constexpr std::chrono::leap_second
+test_leap_second_create(const std::chrono::sys_seconds& date, const 
std::chrono::seconds& value) {
+  return 
std::chrono::leap_second{std::chrono::leap_second::__constructor_tag{}, date, 
value};
+}
+
+#else // _LIBCPP_VERSION
+#  error "Please create a vendor specific version of the test functions and 
file a review at https://reviews.llvm.org/";

ldionne wrote:

This link is outdated now.

https://github.com/llvm/llvm-project/pull/82113
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [libcxx] [libc++][chrono] Loads leap-seconds.list in tzdb. (PR #82113)

2024-02-27 Thread Louis Dionne via llvm-branch-commits

https://github.com/ldionne requested changes to this pull request.


https://github.com/llvm/llvm-project/pull/82113
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [libcxx] [libc++][chrono] Loads leap-seconds.list in tzdb. (PR #82113)

2024-02-27 Thread Louis Dionne via llvm-branch-commits


@@ -0,0 +1,53 @@
+// -*- C++ -*-
+//===--===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#ifndef SUPPORT_TEST_CHRONO_LEAP_SECOND_HPP
+#define SUPPORT_TEST_CHRONO_LEAP_SECOND_HPP
+
+/**
+ * @file Helper functions to create a @ref std::chrono::leap_second.

ldionne wrote:

This looks a bit odd since we don't use Doxygen anywhere in the codebase. I 
would remove the Doxygen style markup.

https://github.com/llvm/llvm-project/pull/82113
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [libcxx] [libc++][chrono] Loads leap-seconds.list in tzdb. (PR #82113)

2024-02-27 Thread Louis Dionne via llvm-branch-commits


@@ -35,5 +35,8 @@ int main(int, const char**) {
   assert(std::ranges::is_sorted(db.links));
   assert(std::ranges::adjacent_find(db.links) == db.links.end()); // is unique?
 
+  assert(!db.leap_seconds.empty());

ldionne wrote:

We seem to be missing a test that the `tzdb` struct has the right members with 
the right types. I think 
`libcxx/test/std/time/time.zone/time.zone.db/time.zone.db.tzdb/tzdb.members.pass.cpp`
 needs to be updated.

https://github.com/llvm/llvm-project/pull/82113
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [libcxx] [libc++][chrono] Loads leap-seconds.list in tzdb. (PR #82113)

2024-02-27 Thread Louis Dionne via llvm-branch-commits


@@ -0,0 +1,56 @@
+//===--===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+// UNSUPPORTED: c++03, c++11, c++14, c++17
+// UNSUPPORTED: no-filesystem, no-localization, no-tzdb
+
+// XFAIL: libcpp-has-no-incomplete-tzdb
+// XFAIL: availability-tzdb-missing
+
+// 
+
+// class leap_second
+// {
+//   leap_second& operator=(const leap_second&) = default;
+//
+//   ...
+// };
+
+#include 
+#include 
+#include 
+
+// Add the include path required by test_chrono_leap_second.h when using 
libc++.
+// ADDITIONAL_COMPILE_FLAGS(stdlib=libc++): -I %S/../../../../../src/include
+#include "test_chrono_leap_second.h"
+
+constexpr bool test() {
+  std::chrono::leap_second a =
+  
test_leap_second_create(std::chrono::sys_seconds{std::chrono::seconds{0}}, 
std::chrono::seconds{1});
+  std::chrono::leap_second b =
+  
test_leap_second_create(std::chrono::sys_seconds{std::chrono::seconds{10}}, 
std::chrono::seconds{15});
+
+  //  operator== only compares the date member.
+  assert(a.date() != b.date());
+  assert(a.value() != b.value());
+
+  b = a;

ldionne wrote:

```suggestion
  std::same_as decltype(auto) result = (b = a);
  assert(&result == &b);
```

Kinda pedantic, but we do it in several places and this ensures that we return 
the right type, and that we return `*this` from the operator.

https://github.com/llvm/llvm-project/pull/82113
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [libcxx] [libc++][chrono] Loads leap-seconds.list in tzdb. (PR #82113)

2024-02-27 Thread Louis Dionne via llvm-branch-commits


@@ -0,0 +1,112 @@
+// -*- C++ -*-
+//===--===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+// For information see https://libcxx.llvm.org/DesignDocs/TimeZone.html
+
+#ifndef _LIBCPP___CHRONO_LEAP_SECOND_H
+#define _LIBCPP___CHRONO_LEAP_SECOND_H
+
+#include 
+// Enable the contents of the header only when libc++ was built with 
experimental features enabled.
+#if !defined(_LIBCPP_HAS_NO_INCOMPLETE_TZDB)
+
+#  include <__chrono/duration.h>
+#  include <__chrono/system_clock.h>
+#  include <__chrono/time_point.h>
+#  include <__compare/ordering.h>
+#  include <__compare/three_way_comparable.h>
+#  include <__config>
+
+#  if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+#pragma GCC system_header
+#  endif
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+#  if _LIBCPP_STD_VER >= 20
+
+namespace chrono {
+
+class leap_second {
+public:
+  struct __constructor_tag;

ldionne wrote:

It would be nice to have a single tag type for private constructors -- we could 
define it library-wide and reuse it whenever we need one.

https://github.com/llvm/llvm-project/pull/82113
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [libcxx] [libc++][chrono] Loads leap-seconds.list in tzdb. (PR #82113)

2024-02-27 Thread Louis Dionne via llvm-branch-commits


@@ -0,0 +1,51 @@
+//===--===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+// UNSUPPORTED: c++03, c++11, c++14, c++17
+// UNSUPPORTED: no-filesystem, no-localization, no-tzdb
+
+// XFAIL: libcpp-has-no-incomplete-tzdb
+// XFAIL: availability-tzdb-missing
+
+// 
+
+// class leap_second
+// {
+//   leap_second(const leap_second&)= default;
+//
+//   ...
+// };
+
+#include 
+#include 
+#include 
+
+// Add the include path required by test_chrono_leap_second.h when using 
libc++.
+// ADDITIONAL_COMPILE_FLAGS(stdlib=libc++): -I %S/../../../../../src/include
+#include "test_chrono_leap_second.h"
+
+constexpr bool test() {
+  std::chrono::leap_second a =
+  
test_leap_second_create(std::chrono::sys_seconds{std::chrono::seconds{0}}, 
std::chrono::seconds{1});
+  std::chrono::leap_second b(a);

ldionne wrote:

```suggestion
  std::chrono::leap_second b = a;
```

I think this would catch the case where the copy ctor is incorrectly marked as 
`explicit`.

https://github.com/llvm/llvm-project/pull/82113
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [libcxx] [libc++][chrono] Loads leap-seconds.list in tzdb. (PR #82113)

2024-02-27 Thread Louis Dionne via llvm-branch-commits


@@ -612,6 +643,16 @@ void __init_tzdb(tzdb& __tzdb, __tz::__rules_storage_type& 
__rules) {
   std::ranges::sort(__tzdb.zones);
   std::ranges::sort(__tzdb.links);
   std::ranges::sort(__rules, {}, [](const auto& p) { return p.first; });
+
+  // There are two files with the leap second information
+  // - leapseconds as specified by zic
+  // - leap-seconds.list the source data
+  // The latter is much easier to parse, it seems Howard shares that
+  // opinion.
+  chrono::__parse_leap_seconds(__tzdb.leap_seconds, ifstream{__root / 
"leap-seconds.list"});
+  // Note the input is sorted, but that does not seem to be are
+  // requirement, it is a requirement in the Standard.
+  std::ranges::sort(__tzdb.leap_seconds);

ldionne wrote:

```suggestion
  // The Standard requires the leap seconds to be sorted.
  // leap-seconds.list usually provides them in sorted order, but that is not
  // guaranteed so we ensure it here.
  std::ranges::sort(__tzdb.leap_seconds);
```

https://github.com/llvm/llvm-project/pull/82113
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [libcxx] [libc++][chrono] Loads leap-seconds.list in tzdb. (PR #82113)

2024-02-27 Thread Louis Dionne via llvm-branch-commits


@@ -0,0 +1,48 @@
+//===--===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+// UNSUPPORTED: c++03, c++11, c++14, c++17
+// UNSUPPORTED: no-filesystem, no-localization, no-tzdb
+
+// XFAIL: libcpp-has-no-incomplete-tzdb
+// XFAIL: availability-tzdb-missing
+
+// 
+
+// class leap_second;
+
+// constexpr sys_seconds date() const noexcept;
+
+#include 
+#include 
+
+#include "test_macros.h"
+
+// Add the include path required by test_chrono_leap_second.h when using 
libc++.
+// ADDITIONAL_COMPILE_FLAGS(stdlib=libc++): -I %S/../../../../../../src/include
+#include "test_chrono_leap_second.h"
+
+constexpr bool test(const std::chrono::leap_second leap_second, 
std::chrono::sys_seconds expected) {
+  std::same_as auto date = leap_second.date();
+  assert(date == expected);
+  static_assert(noexcept(leap_second.date()));
+
+  return true;
+}
+
+int main(int, const char**) {
+  const std::chrono::tzdb& tzdb = std::chrono::get_tzdb();

ldionne wrote:

I think we have two tests here. First, we have a test with 
`test_leap_second_create(std::chrono::sys_seconds{std::chrono::seconds{0}}, 
std::chrono::seconds{1})` and we should test it both at runtime and at 
compile-time.

Second, we have a test with the actual value obtained from `get_tzdb()` and we 
can only test it at runtime.

```c++
constexpr bool test() {
  auto leap_second = 
test_leap_second_create(std::chrono::sys_seconds{std::chrono::seconds{0}}, 
std::chrono::seconds{1});
  std::same_as auto date = leap_second.date();
  assert(date == std::chrono::sys_seconds{std::chrono::seconds{0}});
  // etc..
}

int main() {
  test();
  static_assert(test());

  // test with the real tzdb
  {
const auto& tzdb = get_tzdb();
...
  }
}
```

This would apply to the other test files as well.

https://github.com/llvm/llvm-project/pull/82113
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [libcxx] [libc++][chrono] Loads leap-seconds.list in tzdb. (PR #82113)

2024-02-27 Thread Louis Dionne via llvm-branch-commits


@@ -0,0 +1,53 @@
+// -*- C++ -*-
+//===--===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#ifndef SUPPORT_TEST_CHRONO_LEAP_SECOND_HPP
+#define SUPPORT_TEST_CHRONO_LEAP_SECOND_HPP
+
+/**
+ * @file Helper functions to create a @ref std::chrono::leap_second.
+ *
+ * Since the standard doesn't specify how a @ref std::chrono::leap_second is
+ * constructed this is implementation defined. To make the public API tests of
+ * the class generic this header defines helper functions to create the
+ * required object.
+ *
+ * @note This requires every standard library implementation to write their own
+ * helper function. Vendors are encouraged to create a pull request at
+ * https://github.com/llvm/llvm-project so their specific implementation can be
+ * part of this file.
+ */
+
+#include "test_macros.h"
+
+#if TEST_STD_VER < 20
+#  error "The format header requires at least C++20"
+#endif
+
+#include 
+
+#ifdef _LIBCPP_VERSION
+
+// In order to find this include the calling test needs to provide this path in
+// the search path. Typically this looks like:
+//   REMOVE_THIS_PREFIX__ADDITIONAL_COMPILE_FLAGS(stdlib=libc++): -I 
%S/../../../../../../src/include

ldionne wrote:

```suggestion
//   ADDITIONAL_COMPILE_FLAGS(stdlib=libc++): -I 
%S/../../../../../../src/include
```

This is not necessary to "escape" lit, since this is in a header.

https://github.com/llvm/llvm-project/pull/82113
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [libcxx] [libc++][chrono] Loads leap-seconds.list in tzdb. (PR #82113)

2024-02-27 Thread Louis Dionne via llvm-branch-commits


@@ -0,0 +1,112 @@
+// -*- C++ -*-
+//===--===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+// For information see https://libcxx.llvm.org/DesignDocs/TimeZone.html
+
+#ifndef _LIBCPP___CHRONO_LEAP_SECOND_H
+#define _LIBCPP___CHRONO_LEAP_SECOND_H
+
+#include 
+// Enable the contents of the header only when libc++ was built with 
experimental features enabled.
+#if !defined(_LIBCPP_HAS_NO_INCOMPLETE_TZDB)
+
+#  include <__chrono/duration.h>
+#  include <__chrono/system_clock.h>
+#  include <__chrono/time_point.h>
+#  include <__compare/ordering.h>
+#  include <__compare/three_way_comparable.h>
+#  include <__config>
+
+#  if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+#pragma GCC system_header
+#  endif
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+#  if _LIBCPP_STD_VER >= 20
+
+namespace chrono {
+
+class leap_second {
+public:
+  struct __constructor_tag;
+  [[nodiscard]]
+  _LIBCPP_HIDE_FROM_ABI explicit constexpr leap_second(__constructor_tag&&, 
sys_seconds __date, seconds __value)
+  : __date_(__date), __value_(__value) {}
+
+  _LIBCPP_HIDE_FROM_ABI leap_second(const leap_second&)= default;
+  _LIBCPP_HIDE_FROM_ABI leap_second& operator=(const leap_second&) = default;
+
+  _LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI constexpr sys_seconds date() 
const noexcept { return __date_; }
+
+  _LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI constexpr seconds value() const 
noexcept { return __value_; }
+
+private:
+  sys_seconds __date_;
+  seconds __value_;
+};
+
+_LIBCPP_HIDE_FROM_ABI constexpr bool operator==(const leap_second& __x, const 
leap_second& __y) {

ldionne wrote:

`inline`?

https://github.com/llvm/llvm-project/pull/82113
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [libcxx] [libc++][chrono] Loads leap-seconds.list in tzdb. (PR #82113)

2024-02-27 Thread Louis Dionne via llvm-branch-commits


@@ -0,0 +1,102 @@
+//===--===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+// UNSUPPORTED: c++03, c++11, c++14, c++17
+// UNSUPPORTED: no-filesystem, no-localization, no-tzdb
+
+// XFAIL: libcpp-has-no-incomplete-tzdb
+// XFAIL: availability-tzdb-missing
+
+// 
+
+// Tests the IANA database leap seconds parsing and operations.
+// This is not part of the public tzdb interface.
+
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "assert_macros.h"
+#include "concat_macros.h"
+#include "filesystem_test_helper.h"
+#include "test_tzdb.h"
+
+scoped_test_env env;
+[[maybe_unused]] const std::filesystem::path dir = env.create_dir("zoneinfo");
+const std::filesystem::path tzdata   = 
env.create_file("zoneinfo/tzdata.zi");
+const std::filesystem::path leap_seconds = 
env.create_file("zoneinfo/leap-seconds.list");
+
+std::string_view std::chrono::__libcpp_tzdb_directory() {
+  static std::string result = dir.string();
+  return result;
+}
+
+void write(std::string_view input) {
+  static int version = 0;
+
+  std::ofstream f{tzdata};
+  f << "# version " << version++ << '\n';
+  std::ofstream{leap_seconds}.write(input.data(), input.size());
+}
+
+static const std::chrono::tzdb& parse(std::string_view input) {
+  write(input);
+  return std::chrono::reload_tzdb();
+}
+
+static void test_exception(std::string_view input, [[maybe_unused]] 
std::string_view what) {
+  write(input);
+
+  TEST_VALIDATE_EXCEPTION(
+  std::runtime_error,
+  [&]([[maybe_unused]] const std::runtime_error& e) {
+TEST_LIBCPP_REQUIRE(
+e.what() == what,
+TEST_WRITE_CONCATENATED("\nExpected exception ", what, "\nActual 
exception   ", e.what(), '\n'));
+  },
+  TEST_IGNORE_NODISCARD std::chrono::reload_tzdb());
+}
+
+static void test_invalid() {
+  test_exception("0", "corrupt tzdb: expected a non-zero digit");
+
+  test_exception("1", "corrupt tzdb: expected whitespace");
+
+  test_exception("1 ", "corrupt tzdb: expected a non-zero digit");
+}
+
+static void test_leap_seconds() {
+  using namespace std::chrono;
+
+  const tzdb& result = parse(
+  R"(
+2272060800  10  # 1 Jan 1972
+2287785600  11  # 1 Jul 1972
+2303683200  12  # 1 Jan 1973

ldionne wrote:

You could provide them unordered to test the sorting logic.

Also, what about testing a date before 1970?

https://github.com/llvm/llvm-project/pull/82113
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits