[llvm-branch-commits] [libcxx] [libc++][TZDB] Implements zoned_traits. (PR #91059)

2024-05-04 Thread Mark de Wever via llvm-branch-commits

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

Implements parts of:
- P0355 Extending chrono to Calendars and Time Zones

>From 0a602d2268923936a62034faaaf10f2401457d99 Mon Sep 17 00:00:00 2001
From: Mark de Wever 
Date: Wed, 17 Apr 2024 21:00:22 +0200
Subject: [PATCH] [libc++][TZDB] Implements zoned_traits.

Implements parts of:
- P0355 Extending chrono to Calendars and Time Zones
---
 libcxx/include/CMakeLists.txt |  1 +
 libcxx/include/__chrono/zoned_time.h  | 55 +++
 libcxx/include/chrono |  4 ++
 libcxx/include/module.modulemap   |  1 +
 libcxx/modules/std/chrono.inc |  3 +-
 .../diagnostics/chrono.nodiscard.verify.cpp   |  6 ++
 .../const_time_zone_default_zone.pass.cpp | 36 
 .../const_time_zone_locate_zone.pass.cpp  | 45 +++
 .../types.compile.pass.cpp| 32 +++
 9 files changed, 181 insertions(+), 2 deletions(-)
 create mode 100644 libcxx/include/__chrono/zoned_time.h
 create mode 100644 
libcxx/test/std/time/time.zone/time.zone.zonedtraits/const_time_zone_default_zone.pass.cpp
 create mode 100644 
libcxx/test/std/time/time.zone/time.zone.zonedtraits/const_time_zone_locate_zone.pass.cpp
 create mode 100644 
libcxx/test/std/time/time.zone/time.zone.zonedtraits/types.compile.pass.cpp

diff --git a/libcxx/include/CMakeLists.txt b/libcxx/include/CMakeLists.txt
index 386bd967eed7ab..919f1ae39390a8 100644
--- a/libcxx/include/CMakeLists.txt
+++ b/libcxx/include/CMakeLists.txt
@@ -291,6 +291,7 @@ set(files
   __chrono/year_month.h
   __chrono/year_month_day.h
   __chrono/year_month_weekday.h
+  __chrono/zoned_time.h
   __compare/common_comparison_category.h
   __compare/compare_partial_order_fallback.h
   __compare/compare_strong_order_fallback.h
diff --git a/libcxx/include/__chrono/zoned_time.h 
b/libcxx/include/__chrono/zoned_time.h
new file mode 100644
index 00..c6084426ad72b4
--- /dev/null
+++ b/libcxx/include/__chrono/zoned_time.h
@@ -0,0 +1,55 @@
+// -*- 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_ZONED_TIME_H
+#define _LIBCPP___CHRONO_ZONED_TIME_H
+
+#include 
+// Enable the contents of the header only when libc++ was built with 
experimental features enabled.
+#if !defined(_LIBCPP_HAS_NO_EXPERIMENTAL_TZDB)
+
+#  include <__chrono/time_zone.h>
+#  include <__chrono/tzdb_list.h>
+#  include <__config>
+#  include <__fwd/string_view.h>
+
+#  if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+#pragma GCC system_header
+#  endif
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+#  if _LIBCPP_STD_VER >= 20 && !defined(_LIBCPP_HAS_NO_TIME_ZONE_DATABASE) && 
!defined(_LIBCPP_HAS_NO_FILESYSTEM) &&   \
+  !defined(_LIBCPP_HAS_NO_LOCALIZATION)
+
+namespace chrono {
+
+template 
+struct zoned_traits {};
+
+template <>
+struct zoned_traits {
+  [[nodiscard]] _LIBCPP_HIDE_FROM_ABI static const time_zone* default_zone() { 
return chrono::locate_zone("UTC"); }
+  [[nodiscard]] _LIBCPP_HIDE_FROM_ABI static const time_zone* 
locate_zone(string_view __name) {
+return chrono::locate_zone(__name);
+  }
+};
+
+} // namespace chrono
+
+#  endif // _LIBCPP_STD_VER >= 20 && 
!defined(_LIBCPP_HAS_NO_TIME_ZONE_DATABASE) && 
!defined(_LIBCPP_HAS_NO_FILESYSTEM)
+ // && !defined(_LIBCPP_HAS_NO_LOCALIZATION)
+
+_LIBCPP_END_NAMESPACE_STD
+
+#endif // !defined(_LIBCPP_HAS_NO_EXPERIMENTAL_TZDB)
+
+#endif // _LIBCPP___CHRONO_ZONED_TIME_H
diff --git a/libcxx/include/chrono b/libcxx/include/chrono
index d6b889cdde73c4..7d341823755ffb 100644
--- a/libcxx/include/chrono
+++ b/libcxx/include/chrono
@@ -786,6 +786,9 @@ class time_zone {
 bool operator==(const time_zone& x, const time_zone& y) noexcept;  
  // C++20
 strong_ordering operator<=>(const time_zone& x, const time_zone& y) noexcept;  
  // C++20
 
+// [time.zone.zonedtraits], class template zoned_traits
+template struct zoned_traits; 
  // C++20
+
 // [time.zone.leap], leap second support
 class leap_second {
  // C++20
 public:
@@ -959,6 +962,7 @@ constexpr chrono::year  
operator ""y(unsigned lo
 #include <__chrono/time_zone_link.h>
 #include <__chrono/tzdb.h>
 #include <__chrono/tzdb_list.h>
+#include <__chrono/zoned_time.h>
 #  endif
 
 #endif
diff --git a/libcxx/include/module.modulemap b/libcxx/include/module.modulemap
index e4c154d99602b8..5c0da3e8172571 100644
--- 

[llvm-branch-commits] [libcxx] [libc++][TZDB] Implements time_zone::to_local. (PR #91003)

2024-05-03 Thread Mark de Wever via llvm-branch-commits

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

Implements parts of:
- P0355 Extending chrono to Calendars and Time Zones

>From 5f205f7478a13a6f7034808dff390c3fe87564dc Mon Sep 17 00:00:00 2001
From: Mark de Wever 
Date: Wed, 17 Apr 2024 21:00:22 +0200
Subject: [PATCH] [libc++][TZDB] Implements time_zone::to_local.

Implements parts of:
- P0355 Extending chrono to Calendars and Time Zones
---
 libcxx/include/__chrono/time_zone.h   | 18 +
 libcxx/include/chrono |  4 ++
 .../assert.to_local.pass.cpp  | 40 +++
 .../time.zone.members/to_local.pass.cpp   | 66 +++
 4 files changed, 128 insertions(+)
 create mode 100644 
libcxx/test/libcxx/time/time.zone/time.zone.timezone/time.zone.members/assert.to_local.pass.cpp
 create mode 100644 
libcxx/test/std/time/time.zone/time.zone.timezone/time.zone.members/to_local.pass.cpp

diff --git a/libcxx/include/__chrono/time_zone.h 
b/libcxx/include/__chrono/time_zone.h
index a18c5d5295b7d6..620d880299635c 100644
--- a/libcxx/include/__chrono/time_zone.h
+++ b/libcxx/include/__chrono/time_zone.h
@@ -128,6 +128,24 @@ class _LIBCPP_AVAILABILITY_TZDB time_zone {
 return {};
   }
 
+  template 
+  [[nodiscard]] _LIBCPP_HIDE_FROM_ABI local_time>
+  to_local(const sys_time<_Duration>& __time) const {
+using _Dp = common_type_t<_Duration, seconds>;
+
+sys_info __info = get_info(__time);
+
+_LIBCPP_ASSERT_ARGUMENT_WITHIN_DOMAIN(
+__info.offset >= chrono::seconds{0} || __time.time_since_epoch() >= 
_Dp::min() - __info.offset,
+"cannot convert the system time; it would be before the minimum local 
clock value");
+
+_LIBCPP_ASSERT_ARGUMENT_WITHIN_DOMAIN(
+__info.offset <= chrono::seconds{0} || __time.time_since_epoch() <= 
_Dp::max() - __info.offset,
+"cannot convert the system time; it would be after the maximum local 
clock value");
+
+return local_time<_Dp>{__time.time_since_epoch() + __info.offset};
+  }
+
   [[nodiscard]] _LIBCPP_HIDE_FROM_ABI const __impl& __implementation() const 
noexcept { return *__impl_; }
 
 private:
diff --git a/libcxx/include/chrono b/libcxx/include/chrono
index c70b241f086464..d6b889cdde73c4 100644
--- a/libcxx/include/chrono
+++ b/libcxx/include/chrono
@@ -778,6 +778,10 @@ class time_zone {
   template
   sys_time>
 to_sys(const local_time& tp, choose z) const;
+
+  template
+  local_time>
+to_local(const sys_time& tp) const;
 };
 bool operator==(const time_zone& x, const time_zone& y) noexcept;  
  // C++20
 strong_ordering operator<=>(const time_zone& x, const time_zone& y) noexcept;  
  // C++20
diff --git 
a/libcxx/test/libcxx/time/time.zone/time.zone.timezone/time.zone.members/assert.to_local.pass.cpp
 
b/libcxx/test/libcxx/time/time.zone/time.zone.timezone/time.zone.members/assert.to_local.pass.cpp
new file mode 100644
index 00..d9ca1c80751cce
--- /dev/null
+++ 
b/libcxx/test/libcxx/time/time.zone/time.zone.timezone/time.zone.members/assert.to_local.pass.cpp
@@ -0,0 +1,40 @@
+//===--===//
+//
+// 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
+
+// REQUIRES: has-unix-headers
+// REQUIRES: libcpp-hardening-mode={{extensive|debug}}
+// XFAIL: libcpp-hardening-mode=debug && availability-verbose_abort-missing
+
+// XFAIL: libcpp-has-no-experimental-tzdb
+// XFAIL: availability-tzdb-missing
+
+// 
+
+// template 
+// local_time>
+//   to_local(const sys_time& tp) const;
+
+#include 
+
+#include "check_assertion.h"
+
+// Tests values that cannot be converted. To make sure the test is does not 
depend on changes
+// in the database it uses a time zone with a fixed offset.
+int main(int, char**) {
+  
TEST_LIBCPP_ASSERT_FAILURE(std::chrono::locate_zone("Etc/GMT+1")->to_local(std::chrono::sys_seconds::min()),
+ "cannot convert the system time; it would be 
before the minimum local clock value");
+
+  // TODO TZDB look why std::chrono::sys_seconds::max()  fails
+  TEST_LIBCPP_ASSERT_FAILURE(
+  
std::chrono::locate_zone("Etc/GMT-1")->to_local(std::chrono::sys_seconds::max() 
- std::chrono::seconds(1)),
+  "cannot convert the system time; it would be after the maximum local 
clock value");
+
+  return 0;
+}
diff --git 
a/libcxx/test/std/time/time.zone/time.zone.timezone/time.zone.members/to_local.pass.cpp
 
b/libcxx/test/std/time/time.zone/time.zone.timezone/time.zone.members/to_local.pass.cpp
new file mode 100644
index 00..dfeea244f7e38e
--- /dev/null
+++ 
b/libcxx/test/std/time/time.zone/time.zone.timezone/time.zone.members/to_local.pass.cpp
@@ -0,0 +1,66 @@

[llvm-branch-commits] [libcxx] [libc++][TZDB] Implements time_zone::to_sys. (PR #90901)

2024-05-03 Thread Mark de Wever via llvm-branch-commits

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

>From 775f5459258db3416e90dbe0f8b0ee24f7125e95 Mon Sep 17 00:00:00 2001
From: Mark de Wever 
Date: Wed, 17 Apr 2024 21:00:22 +0200
Subject: [PATCH] [libc++][TZDB] Implements time_zone::to_sys.

This implements the overload with the choose argument and adds this enum.

Implements parts of:
- P0355 Extending chrono to Calendars and Time Zones
---
 libcxx/include/__chrono/time_zone.h   |  32 
 libcxx/include/chrono |   4 +
 libcxx/modules/std/chrono.inc |   3 -
 .../diagnostics/chrono.nodiscard.verify.cpp   |   3 +
 .../time.zone.timezone/choose.pass.cpp|  37 +
 .../assert.to_sys_choose.pass.cpp |  41 +
 .../time.zone.members/to_sys_choose.pass.cpp  | 147 ++
 7 files changed, 264 insertions(+), 3 deletions(-)
 create mode 100644 
libcxx/test/libcxx/time/time.zone/time.zone.timezone/choose.pass.cpp
 create mode 100644 
libcxx/test/libcxx/time/time.zone/time.zone.timezone/time.zone.members/assert.to_sys_choose.pass.cpp
 create mode 100644 
libcxx/test/std/time/time.zone/time.zone.timezone/time.zone.members/to_sys_choose.pass.cpp

diff --git a/libcxx/include/__chrono/time_zone.h 
b/libcxx/include/__chrono/time_zone.h
index b7ce4ea659a1af..a18c5d5295b7d6 100644
--- a/libcxx/include/__chrono/time_zone.h
+++ b/libcxx/include/__chrono/time_zone.h
@@ -42,6 +42,8 @@ _LIBCPP_BEGIN_NAMESPACE_STD
 
 namespace chrono {
 
+enum class choose { earliest, latest };
+
 class _LIBCPP_AVAILABILITY_TZDB time_zone {
   _LIBCPP_HIDE_FROM_ABI time_zone() = default;
 
@@ -96,6 +98,36 @@ class _LIBCPP_AVAILABILITY_TZDB time_zone {
 return {};
   }
 
+  template 
+  [[nodiscard]] _LIBCPP_HIDE_FROM_ABI sys_time>
+  to_sys(const local_time<_Duration>& __time, choose __z) const {
+local_info __info = get_info(__time);
+switch (__info.result) {
+case local_info::unique:
+case local_info::nonexistent: // first and second are the same
+  return sys_time>{__time.time_since_epoch() - __info.first.offset};
+
+case local_info::ambiguous:
+  switch (__z) {
+  case choose::earliest:
+return sys_time>{__time.time_since_epoch() - __info.first.offset};
+
+  case choose::latest:
+return sys_time>{__time.time_since_epoch() - __info.second.offset};
+
+// Note a value out of bounds is not specified.
+  }
+}
+
+// TODO TZDB The standard does not specify anything in these cases.
+_LIBCPP_ASSERT_ARGUMENT_WITHIN_DOMAIN(
+__info.result != -1, "cannot convert the local time; it would be 
before the minimum system clock value");
+_LIBCPP_ASSERT_ARGUMENT_WITHIN_DOMAIN(
+__info.result != -2, "cannot convert the local time; it would be after 
the maximum system clock value");
+
+return {};
+  }
+
   [[nodiscard]] _LIBCPP_HIDE_FROM_ABI const __impl& __implementation() const 
noexcept { return *__impl_; }
 
 private:
diff --git a/libcxx/include/chrono b/libcxx/include/chrono
index 4b0ea938710bdd..c70b241f086464 100644
--- a/libcxx/include/chrono
+++ b/libcxx/include/chrono
@@ -774,6 +774,10 @@ class time_zone {
   template
   sys_time>
 to_sys(const local_time& tp) const;
+
+  template
+  sys_time>
+to_sys(const local_time& tp, choose z) const;
 };
 bool operator==(const time_zone& x, const time_zone& y) noexcept;  
  // C++20
 strong_ordering operator<=>(const time_zone& x, const time_zone& y) noexcept;  
  // C++20
diff --git a/libcxx/modules/std/chrono.inc b/libcxx/modules/std/chrono.inc
index 38e3c4184521b7..9e16f09bd31afb 100644
--- a/libcxx/modules/std/chrono.inc
+++ b/libcxx/modules/std/chrono.inc
@@ -216,11 +216,8 @@ export namespace std {
 using std::chrono::local_info;
 using std::chrono::sys_info;
 
-#if 0
 // [time.zone.timezone], class time_zone
 using std::chrono::choose;
-#endif // if 0
-
 using std::chrono::time_zone;
 
 #if 0
diff --git a/libcxx/test/libcxx/diagnostics/chrono.nodiscard.verify.cpp 
b/libcxx/test/libcxx/diagnostics/chrono.nodiscard.verify.cpp
index fea1e4417cc12c..cba7916ff2c646 100644
--- a/libcxx/test/libcxx/diagnostics/chrono.nodiscard.verify.cpp
+++ b/libcxx/test/libcxx/diagnostics/chrono.nodiscard.verify.cpp
@@ -49,9 +49,12 @@ void test() {
   {
 std::chrono::sys_seconds s{};
 std::chrono::local_seconds l{};
+std::chrono::choose z = std::chrono::choose::earliest;
 tz.name();   // expected-warning {{ignoring return value of 
function declared with 'nodiscard' attribute}}
 tz.get_info(s);  // expected-warning {{ignoring return value of 
function declared with 'nodiscard' attribute}}
 tz.get_info(l);  // expected-warning {{ignoring return value of 
function declared with 'nodiscard' attribute}}
+tz.to_sys(l);// not nodiscard
+tz.to_sys(l, z); // expected-warning {{ignoring return value of 
function declared with 'nodiscard' attribute}}
 

[llvm-branch-commits] [libcxx] [libc++][TZDB] Implements time_zone::to_sys. (PR #90901)

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

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

This implements the overload with the choose argument and adds this enum.

Implements parts of:
- P0355 Extending chrono to Calendars and Time Zones

>From b888e3cc20a9198578348ac3bf3f6d505425a63c Mon Sep 17 00:00:00 2001
From: Mark de Wever 
Date: Wed, 17 Apr 2024 21:00:22 +0200
Subject: [PATCH] [libc++][TZDB] Implements time_zone::to_sys.

This implements the overload with the choose argument and adds this enum.

Implements parts of:
- P0355 Extending chrono to Calendars and Time Zones
---
 libcxx/include/__chrono/time_zone.h   |  33 
 libcxx/include/chrono |   4 +
 libcxx/modules/std/chrono.inc |   3 -
 .../diagnostics/chrono.nodiscard.verify.cpp   |   3 +
 .../time.zone.timezone/choose.pass.cpp|  37 +
 .../assert.to_sys_choose.pass.cpp |  41 +
 .../time.zone.members/to_sys_choose.pass.cpp  | 147 ++
 7 files changed, 265 insertions(+), 3 deletions(-)
 create mode 100644 
libcxx/test/libcxx/time/time.zone/time.zone.timezone/choose.pass.cpp
 create mode 100644 
libcxx/test/libcxx/time/time.zone/time.zone.timezone/time.zone.members/assert.to_sys_choose.pass.cpp
 create mode 100644 
libcxx/test/std/time/time.zone/time.zone.timezone/time.zone.members/to_sys_choose.pass.cpp

diff --git a/libcxx/include/__chrono/time_zone.h 
b/libcxx/include/__chrono/time_zone.h
index b7ce4ea659a1af..ec0eee44c3b6f9 100644
--- a/libcxx/include/__chrono/time_zone.h
+++ b/libcxx/include/__chrono/time_zone.h
@@ -42,6 +42,8 @@ _LIBCPP_BEGIN_NAMESPACE_STD
 
 namespace chrono {
 
+enum class choose { earliest, latest };
+
 class _LIBCPP_AVAILABILITY_TZDB time_zone {
   _LIBCPP_HIDE_FROM_ABI time_zone() = default;
 
@@ -96,6 +98,37 @@ class _LIBCPP_AVAILABILITY_TZDB time_zone {
 return {};
   }
 
+  template 
+  [[nodiscard]] _LIBCPP_HIDE_FROM_ABI sys_time>
+  to_sys(const local_time<_Duration>& __time, choose __z) const {
+local_info __info = get_info(__time);
+switch (__info.result) {
+case local_info::unique:
+case local_info::nonexistent: // first and second are the same
+  return sys_time>{__time.time_since_epoch() - __info.first.offset};
+
+case local_info::ambiguous:
+  switch (__z) {
+  case choose::earliest:
+return sys_time>{__time.time_since_epoch() - __info.first.offset};
+
+  case choose::latest:
+return sys_time>{__time.time_since_epoch() - __info.second.offset};
+
+// Note a value out of bounds is not specified.
+  }
+  [[fallthrough]];
+}
+
+// TODO TZDB The standard does not specify anything in these cases.
+_LIBCPP_ASSERT_ARGUMENT_WITHIN_DOMAIN(
+__info.result != -1, "cannot convert the local time; it would be 
before the minimum system clock value");
+_LIBCPP_ASSERT_ARGUMENT_WITHIN_DOMAIN(
+__info.result != -2, "cannot convert the local time; it would be after 
the maximum system clock value");
+
+return {};
+  }
+
   [[nodiscard]] _LIBCPP_HIDE_FROM_ABI const __impl& __implementation() const 
noexcept { return *__impl_; }
 
 private:
diff --git a/libcxx/include/chrono b/libcxx/include/chrono
index 4b0ea938710bdd..c70b241f086464 100644
--- a/libcxx/include/chrono
+++ b/libcxx/include/chrono
@@ -774,6 +774,10 @@ class time_zone {
   template
   sys_time>
 to_sys(const local_time& tp) const;
+
+  template
+  sys_time>
+to_sys(const local_time& tp, choose z) const;
 };
 bool operator==(const time_zone& x, const time_zone& y) noexcept;  
  // C++20
 strong_ordering operator<=>(const time_zone& x, const time_zone& y) noexcept;  
  // C++20
diff --git a/libcxx/modules/std/chrono.inc b/libcxx/modules/std/chrono.inc
index 38e3c4184521b7..9e16f09bd31afb 100644
--- a/libcxx/modules/std/chrono.inc
+++ b/libcxx/modules/std/chrono.inc
@@ -216,11 +216,8 @@ export namespace std {
 using std::chrono::local_info;
 using std::chrono::sys_info;
 
-#if 0
 // [time.zone.timezone], class time_zone
 using std::chrono::choose;
-#endif // if 0
-
 using std::chrono::time_zone;
 
 #if 0
diff --git a/libcxx/test/libcxx/diagnostics/chrono.nodiscard.verify.cpp 
b/libcxx/test/libcxx/diagnostics/chrono.nodiscard.verify.cpp
index fea1e4417cc12c..cba7916ff2c646 100644
--- a/libcxx/test/libcxx/diagnostics/chrono.nodiscard.verify.cpp
+++ b/libcxx/test/libcxx/diagnostics/chrono.nodiscard.verify.cpp
@@ -49,9 +49,12 @@ void test() {
   {
 std::chrono::sys_seconds s{};
 std::chrono::local_seconds l{};
+std::chrono::choose z = std::chrono::choose::earliest;
 tz.name();   // expected-warning {{ignoring return value of 
function declared with 'nodiscard' attribute}}
 tz.get_info(s);  // expected-warning {{ignoring return value of 
function declared with 'nodiscard' attribute}}
 tz.get_info(l);  // expected-warning {{ignoring return value of 
function declared with 'nodiscard' 

[llvm-branch-commits] [libcxx] release/18.x: [libcxx] [modules] Add _LIBCPP_USING_IF_EXISTS on aligned_alloc (#89827) (PR #89894)

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

mordante wrote:

I don't feel like this needs a release note.

https://github.com/llvm/llvm-project/pull/89894
___
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++][TZDB] Implements time_zone::to_sys. (PR #90394)

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

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

>From d7b42718303e017acfe3e61c67d6e8a9bb0ffa9d Mon Sep 17 00:00:00 2001
From: Mark de Wever 
Date: Wed, 17 Apr 2024 21:00:22 +0200
Subject: [PATCH] [libc++][TZDB] Implements time_zone::to_sys.

This implements the throwing overload and the exception classes throw by
this overload.

Implements parts of:
- P0355 Extending chrono to Calendars and Time Zones
---
 libcxx/include/CMakeLists.txt |   1 +
 libcxx/include/__chrono/exception.h   | 129 ++
 libcxx/include/__chrono/time_zone.h   |  26 ++
 libcxx/include/chrono |   9 +
 libcxx/include/module.modulemap   |   6 +-
 libcxx/modules/std/chrono.inc |   2 -
 libcxx/src/CMakeLists.txt |   3 +
 libcxx/src/chrono_exception.cpp   |  20 ++
 .../assert.ctor.pass.cpp  |  53 
 .../assert.ctor.pass.cpp  |  53 
 .../time.zone.members/assert.to_sys.pass.cpp  |  39 +++
 .../test/libcxx/transitive_includes/cxx03.csv |   3 -
 .../test/libcxx/transitive_includes/cxx11.csv |   3 -
 .../test/libcxx/transitive_includes/cxx14.csv |   3 -
 .../test/libcxx/transitive_includes/cxx17.csv |   3 -
 .../test/libcxx/transitive_includes/cxx20.csv |   8 +-
 .../test/libcxx/transitive_includes/cxx23.csv |  12 +-
 .../test/libcxx/transitive_includes/cxx26.csv |  12 +-
 .../time.zone.exception.ambig/ctor.pass.cpp   | 171 +
 .../types.compile.pass.cpp|  33 +++
 .../ctor.pass.cpp | 172 +
 .../types.compile.pass.cpp|  33 +++
 .../time.zone.members/to_sys.pass.cpp | 237 ++
 23 files changed, 987 insertions(+), 44 deletions(-)
 create mode 100644 libcxx/include/__chrono/exception.h
 create mode 100644 libcxx/src/chrono_exception.cpp
 create mode 100644 
libcxx/test/libcxx/time/time.zone/time.zone.exception/time.zone.exception.ambig/assert.ctor.pass.cpp
 create mode 100644 
libcxx/test/libcxx/time/time.zone/time.zone.exception/time.zone.exception.nonexist/assert.ctor.pass.cpp
 create mode 100644 
libcxx/test/libcxx/time/time.zone/time.zone.timezone/time.zone.members/assert.to_sys.pass.cpp
 create mode 100644 
libcxx/test/std/time/time.zone/time.zone.exception/time.zone.exception.ambig/ctor.pass.cpp
 create mode 100644 
libcxx/test/std/time/time.zone/time.zone.exception/time.zone.exception.ambig/types.compile.pass.cpp
 create mode 100644 
libcxx/test/std/time/time.zone/time.zone.exception/time.zone.exception.nonexist/ctor.pass.cpp
 create mode 100644 
libcxx/test/std/time/time.zone/time.zone.exception/time.zone.exception.nonexist/types.compile.pass.cpp
 create mode 100644 
libcxx/test/std/time/time.zone/time.zone.timezone/time.zone.members/to_sys.pass.cpp

diff --git a/libcxx/include/CMakeLists.txt b/libcxx/include/CMakeLists.txt
index 1296c536bc882c..386bd967eed7ab 100644
--- a/libcxx/include/CMakeLists.txt
+++ b/libcxx/include/CMakeLists.txt
@@ -264,6 +264,7 @@ set(files
   __chrono/convert_to_tm.h
   __chrono/day.h
   __chrono/duration.h
+  __chrono/exception.h
   __chrono/file_clock.h
   __chrono/formatter.h
   __chrono/hh_mm_ss.h
diff --git a/libcxx/include/__chrono/exception.h 
b/libcxx/include/__chrono/exception.h
new file mode 100644
index 00..6059a62c3b2ea9
--- /dev/null
+++ b/libcxx/include/__chrono/exception.h
@@ -0,0 +1,129 @@
+// -*- 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_EXCEPTION_H
+#define _LIBCPP___CHRONO_EXCEPTION_H
+
+#include 
+// Enable the contents of the header only when libc++ was built with 
experimental features enabled.
+#if !defined(_LIBCPP_HAS_NO_EXPERIMENTAL_TZDB)
+
+#  include <__availability>
+#  include <__chrono/calendar.h>
+#  include <__chrono/local_info.h>
+#  include <__chrono/time_point.h>
+#  include <__config>
+#  include <__verbose_abort>
+#  include 
+#  include 
+#  include 
+
+#  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 nonexistent_local_time : public runtime_error {
+public:
+  template 
+  _LIBCPP_HIDE_FROM_ABI nonexistent_local_time(const local_time<_Duration>& 
__time, const local_info& __info)
+  : runtime_error{__create_message(__time, __info)} {
+// [time.zone.exception.nonexist]/2
+//   Preconditions: i.result == local_info::nonexistent is true.
+// The value of 

[llvm-branch-commits] [libcxx] [libc++][TZDB] Implements time_zone::to_sys. (PR #90394)

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

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

>From e72a966c0aca3319d7aea43d3a9dd4cc25eaeb70 Mon Sep 17 00:00:00 2001
From: Mark de Wever 
Date: Wed, 17 Apr 2024 21:00:22 +0200
Subject: [PATCH] [libc++][TZDB] Implements time_zone::to_sys.

This implements the throwing overload and the exception classes throw by
this overload.

Implements parts of:
- P0355 Extending chrono to Calendars and Time Zones
---
 libcxx/include/CMakeLists.txt |   1 +
 libcxx/include/__chrono/exception.h   | 129 ++
 libcxx/include/__chrono/time_zone.h   |  26 ++
 libcxx/include/chrono |   9 +
 libcxx/include/module.modulemap   |   6 +-
 libcxx/modules/std/chrono.inc |   2 -
 libcxx/src/CMakeLists.txt |   3 +
 libcxx/src/chrono_exception.cpp   |  20 ++
 .../assert.ctor.pass.cpp  |  53 
 .../assert.ctor.pass.cpp  |  53 
 .../time.zone.members/assert.to_sys.pass.cpp  |  39 +++
 .../test/libcxx/transitive_includes/cxx03.csv |   3 -
 .../test/libcxx/transitive_includes/cxx11.csv |   3 -
 .../test/libcxx/transitive_includes/cxx14.csv |   3 -
 .../test/libcxx/transitive_includes/cxx17.csv |   3 -
 .../test/libcxx/transitive_includes/cxx20.csv |   8 +-
 .../test/libcxx/transitive_includes/cxx23.csv |  12 +-
 .../test/libcxx/transitive_includes/cxx26.csv |  12 +-
 .../time.zone.exception.ambig/ctor.pass.cpp   | 171 +
 .../types.compile.pass.cpp|  32 +++
 .../ctor.pass.cpp | 172 +
 .../types.compile.pass.cpp|  32 +++
 .../time.zone.members/to_sys.pass.cpp | 237 ++
 23 files changed, 985 insertions(+), 44 deletions(-)
 create mode 100644 libcxx/include/__chrono/exception.h
 create mode 100644 libcxx/src/chrono_exception.cpp
 create mode 100644 
libcxx/test/libcxx/time/time.zone/time.zone.exception/time.zone.exception.ambig/assert.ctor.pass.cpp
 create mode 100644 
libcxx/test/libcxx/time/time.zone/time.zone.exception/time.zone.exception.nonexist/assert.ctor.pass.cpp
 create mode 100644 
libcxx/test/libcxx/time/time.zone/time.zone.timezone/time.zone.members/assert.to_sys.pass.cpp
 create mode 100644 
libcxx/test/std/time/time.zone/time.zone.exception/time.zone.exception.ambig/ctor.pass.cpp
 create mode 100644 
libcxx/test/std/time/time.zone/time.zone.exception/time.zone.exception.ambig/types.compile.pass.cpp
 create mode 100644 
libcxx/test/std/time/time.zone/time.zone.exception/time.zone.exception.nonexist/ctor.pass.cpp
 create mode 100644 
libcxx/test/std/time/time.zone/time.zone.exception/time.zone.exception.nonexist/types.compile.pass.cpp
 create mode 100644 
libcxx/test/std/time/time.zone/time.zone.timezone/time.zone.members/to_sys.pass.cpp

diff --git a/libcxx/include/CMakeLists.txt b/libcxx/include/CMakeLists.txt
index 1296c536bc882c..386bd967eed7ab 100644
--- a/libcxx/include/CMakeLists.txt
+++ b/libcxx/include/CMakeLists.txt
@@ -264,6 +264,7 @@ set(files
   __chrono/convert_to_tm.h
   __chrono/day.h
   __chrono/duration.h
+  __chrono/exception.h
   __chrono/file_clock.h
   __chrono/formatter.h
   __chrono/hh_mm_ss.h
diff --git a/libcxx/include/__chrono/exception.h 
b/libcxx/include/__chrono/exception.h
new file mode 100644
index 00..6059a62c3b2ea9
--- /dev/null
+++ b/libcxx/include/__chrono/exception.h
@@ -0,0 +1,129 @@
+// -*- 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_EXCEPTION_H
+#define _LIBCPP___CHRONO_EXCEPTION_H
+
+#include 
+// Enable the contents of the header only when libc++ was built with 
experimental features enabled.
+#if !defined(_LIBCPP_HAS_NO_EXPERIMENTAL_TZDB)
+
+#  include <__availability>
+#  include <__chrono/calendar.h>
+#  include <__chrono/local_info.h>
+#  include <__chrono/time_point.h>
+#  include <__config>
+#  include <__verbose_abort>
+#  include 
+#  include 
+#  include 
+
+#  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 nonexistent_local_time : public runtime_error {
+public:
+  template 
+  _LIBCPP_HIDE_FROM_ABI nonexistent_local_time(const local_time<_Duration>& 
__time, const local_info& __info)
+  : runtime_error{__create_message(__time, __info)} {
+// [time.zone.exception.nonexist]/2
+//   Preconditions: i.result == local_info::nonexistent is true.
+// The value of 

[llvm-branch-commits] [libcxx] [libc++][chrono] implements UTC clock. (PR #90393)

2024-05-01 Thread Mark de Wever via llvm-branch-commits


@@ -0,0 +1,1004 @@
+//===--===//
+// 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
+// UNSUPPORTED: GCC-ALWAYS_INLINE-FIXME
+
+// TODO FMT This test should not require std::to_chars(floating-point)
+// XFAIL: availability-fp_to_chars-missing
+
+// XFAIL: libcpp-has-no-incomplete-tzdb
+// XFAIL: availability-tzdb-missing
+
+// REQUIRES: locale.fr_FR.UTF-8
+// REQUIRES: locale.ja_JP.UTF-8
+
+// 
+
+// template
+//   struct formatter, charT>;
+
+#include 
+#include 
+
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "formatter_tests.h"
+#include "make_string.h"
+#include "platform_support.h" // locale name macros
+#include "test_macros.h"
+
+template 
+static void test_no_chrono_specs() {
+  using namespace std::literals::chrono_literals;
+
+  std::locale::global(std::locale(LOCALE_fr_FR_UTF_8));
+
+  // Non localized output
+
+  // [time.syn]
+  //   using nanoseconds  = duration;
+  //   using microseconds = duration;
+  //   using milliseconds = duration;
+  //   using seconds  = duration;
+  //   using minutes  = duration>;
+  //   using hours= duration>;
+  check(SV("1425-08-04 22:06:56"), SV("{}"), 
std::chrono::utc_seconds(-17'179'869'184s)); // Minimum value for 35 bits.
+  check(SV("1901-12-13 20:45:52"), SV("{}"), 
std::chrono::utc_seconds(-2'147'483'648s));
+
+  check(SV("1969-12-31 00:00:00"), SV("{}"), std::chrono::utc_seconds(-24h));
+  check(SV("1969-12-31 06:00:00"), SV("{}"), std::chrono::utc_seconds(-18h));
+  check(SV("1969-12-31 12:00:00"), SV("{}"), std::chrono::utc_seconds(-12h));
+  check(SV("1969-12-31 18:00:00"), SV("{}"), std::chrono::utc_seconds(-6h));
+  check(SV("1969-12-31 23:59:59"), SV("{}"), std::chrono::utc_seconds(-1s));
+
+  check(SV("1970-01-01 00:00:00"), SV("{}"), std::chrono::utc_seconds(0s));
+  check(SV("2000-01-01 00:00:00"), SV("{}"), 
std::chrono::utc_seconds(946'684'800s + 22s));
+  check(SV("2000-01-01 01:02:03"), SV("{}"), 
std::chrono::utc_seconds(946'688'523s + 22s));
+
+  check(SV("2038-01-19 03:14:07"), SV("{}"), 
std::chrono::utc_seconds(2'147'483'647s + 27s));
+  check(SV("2514-05-30 01:53:03"),
+SV("{}"),
+std::chrono::utc_seconds(17'179'869'183s + 27s)); // Maximum value for 
35 bits.
+
+  check(SV("2000-01-01 01:02:03.123"),
+SV("{}"),
+std::chrono::utc_time(946'688'523'123ms + 
22s));
+
+  std::locale::global(std::locale::classic());
+}
+
+template 
+static void test_valid_values_year() {
+  using namespace std::literals::chrono_literals;
+
+  constexpr std::basic_string_view fmt =
+  
SV("{:%%C='%C'%t%%EC='%EC'%t%%y='%y'%t%%Oy='%Oy'%t%%Ey='%Ey'%t%%Y='%Y'%t%%EY='%EY'%n}");
+  constexpr std::basic_string_view lfmt =
+  
SV("{:L%%C='%C'%t%%EC='%EC'%t%%y='%y'%t%%Oy='%Oy'%t%%Ey='%Ey'%t%%Y='%Y'%t%%EY='%EY'%n}");
+
+  const std::locale loc(LOCALE_ja_JP_UTF_8);
+  std::locale::global(std::locale(LOCALE_fr_FR_UTF_8));
+
+  // Non localized output using C-locale
+  
check(SV("%C='19'\t%EC='19'\t%y='70'\t%Oy='70'\t%Ey='70'\t%Y='1970'\t%EY='1970'\n"),
+fmt,
+std::chrono::utc_seconds(0s)); // 00:00:00 UTC Thursday, 1 January 1970
+
+  
check(SV("%C='20'\t%EC='20'\t%y='09'\t%Oy='09'\t%Ey='09'\t%Y='2009'\t%EY='2009'\n"),
+fmt,
+std::chrono::utc_seconds(1'234'567'890s)); // 23:31:30 UTC on Friday, 
13 February 2009
+
+  // Use the global locale (fr_FR)
+  
check(SV("%C='19'\t%EC='19'\t%y='70'\t%Oy='70'\t%Ey='70'\t%Y='1970'\t%EY='1970'\n"),
+lfmt,
+std::chrono::utc_seconds(0s)); // 00:00:00 UTC Thursday, 1 January 1970
+
+  
check(SV("%C='20'\t%EC='20'\t%y='09'\t%Oy='09'\t%Ey='09'\t%Y='2009'\t%EY='2009'\n"),
+lfmt,
+std::chrono::utc_seconds(1'234'567'890s)); // 23:31:30 UTC on Friday, 
13 February 2009
+
+  // Use supplied locale (ja_JP). This locale has a different alternate.
+#if defined(_WIN32) || defined(__APPLE__) || defined(_AIX) || 
defined(__FreeBSD__)
+  check(loc,
+
SV("%C='19'\t%EC='19'\t%y='70'\t%Oy='70'\t%Ey='70'\t%Y='1970'\t%EY='1970'\n"),
+lfmt,
+std::chrono::utc_seconds(0s)); // 00:00:00 UTC Thursday, 1 January 1970
+
+  check(loc,
+
SV("%C='20'\t%EC='20'\t%y='09'\t%Oy='09'\t%Ey='09'\t%Y='2009'\t%EY='2009'\n"),
+lfmt,
+std::chrono::utc_seconds(1'234'567'890s)); // 23:31:30 UTC on Friday, 
13 February 2009
+#else  // defined(_WIN32) || defined(__APPLE__) || 
defined(_AIX)||defined(__FreeBSD__)
+  check(loc,
+
SV("%C='19'\t%EC='昭和'\t%y='70'\t%Oy='七十'\t%Ey='45'\t%Y='1970'\t%EY='昭和45年'\n"),
+lfmt,
+

[llvm-branch-commits] [libcxx] [libc++][chrono] implements UTC clock. (PR #90393)

2024-05-01 Thread Mark de Wever via llvm-branch-commits

https://github.com/mordante edited 
https://github.com/llvm/llvm-project/pull/90393
___
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] implements UTC clock. (PR #90393)

2024-05-01 Thread Mark de Wever via llvm-branch-commits

https://github.com/mordante commented:

Thanks for your review comments.

https://github.com/llvm/llvm-project/pull/90393
___
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] implements UTC clock. (PR #90393)

2024-05-01 Thread Mark de Wever via llvm-branch-commits


@@ -0,0 +1,124 @@
+//===--===//
+//
+// 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 utc_clock;
+
+// template
+// leap_second_info get_leap_second_info(const utc_time& ut);
+
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "test_macros.h"
+#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;
+}
+
+static 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());
+}
+
+template 
+static void test_leap_second_info(
+std::chrono::time_point time, bool 
is_leap_second, std::chrono::seconds elapsed) {
+  std::chrono::leap_second_info result = 
std::chrono::get_leap_second_info(time);
+  TEST_REQUIRE(
+  result.is_leap_second == is_leap_second && result.elapsed == elapsed,
+  TEST_WRITE_CONCATENATED(
+  "\nExpected output [",
+  is_leap_second,
+  ", ",
+  elapsed,
+  "]\nActual output   [",
+  result.is_leap_second,
+  ", ",
+  result.elapsed,
+  "]\n"));
+}
+
+// Note at the time of writing all leap seconds are positive. This test uses
+// fake data to test the behaviour of negative leap seconds.
+int main(int, const char**) {
+  using namespace std::literals::chrono_literals;
+
+  // Use small values for simplicity. The dates are seconds since 1.1.1900.
+  write(
+  R"(
+1 10
+60 11
+120 12
+180 11
+240 12
+300 13
+360 12
+)");
+
+  // Transitions from the start of UTC.
+  auto test_transition = [](std::chrono::utc_seconds time, 
std::chrono::seconds elapsed, bool positive) {
+if (positive) {
+  // Every transition has the following tests
+  // - 1ns before the start of the transition is_leap_second -> false, 
elapsed -> elapsed
+  // - at the start of the transition is_leap_second -> true,  
elapsed -> elapsed + 1
+  // - 1ns after  the start of the transition is_leap_second -> true,  
elapsed -> elapsed + 1
+  // - 1ns before the end   of the transition is_leap_second -> true,  
elapsed -> elapsed + 1
+  // - at the end   of the transition is_leap_second -> false, 
elapsed -> elapsed + 1
+
+  test_leap_second_info(time - 1ns, false, elapsed);
+  test_leap_second_info(time, true, elapsed + 1s);
+  test_leap_second_info(time + 1ns, true, elapsed + 1s);
+  test_leap_second_info(time + 1s - 1ns, true, elapsed + 1s);
+  test_leap_second_info(time + 1s, false, elapsed + 1s);
+} else {
+  // Every transition has the following tests
+  // - 1ns before the transition is_leap_second -> false, elapsed -> 
elapsed
+  // - at the transition is_leap_second -> false  elapsed -> 
elapsed - 1
+  // - 1ns after  the transition is_leap_second -> false, elapsed -> 
elapsed - 1
+  test_leap_second_info(time - 1ns, false, elapsed);
+  test_leap_second_info(time, false, elapsed - 1s);
+  test_leap_second_info(time + 1ns, false, elapsed - 1s);
+}
+  };
+
+  std::chrono::utc_seconds epoch{std::chrono::sys_days{std::chrono::January / 
1 / 1900}.time_since_epoch()};
+  test_leap_second_info(epoch, false, 0s);
+
+  // The UTC times are:
+  //   epoch + transition time in the database + leap seconds before the 
transition.
+  test_transition(epoch + 60s + 0s, 0s, true);
+  test_transition(epoch + 120s + 1s, 1s, true);
+  test_transition(epoch + 180s + 2s, 2s, false);

mordante wrote:

Not having negative leap seconds indeed makes it hard to determine their proper 
behaviour. The Standard also is quite silent on them; I can imagine why. I'll 
consider your point and maybe search for other references.

https://github.com/llvm/llvm-project/pull/90393
___
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] implements UTC clock. (PR #90393)

2024-05-01 Thread Mark de Wever via llvm-branch-commits


@@ -0,0 +1,155 @@
+// -*- 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 _LIBCPP___CHRONO_UTC_CLOCK_H
+#define _LIBCPP___CHRONO_UTC_CLOCK_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 <__chrono/tzdb.h>
+#  include <__chrono/tzdb_list.h>
+#  include <__config>
+#  include <__type_traits/common_type.h>
+
+#  if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+#pragma GCC system_header
+#  endif
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+#  if _LIBCPP_STD_VER >= 20 && !defined(_LIBCPP_HAS_NO_TIME_ZONE_DATABASE) && 
!defined(_LIBCPP_HAS_NO_FILESYSTEM) &&   \
+  !defined(_LIBCPP_HAS_NO_LOCALIZATION)
+
+namespace chrono {
+
+class utc_clock;
+
+template 
+using utc_time= time_point;
+using utc_seconds = utc_time;
+
+class utc_clock {
+public:
+  using rep   = system_clock::rep;
+  using period= system_clock::period;
+  using duration  = chrono::duration;
+  using time_point= chrono::time_point;
+  static constexpr bool is_steady = false; // The system_clock is not steady.
+
+  [[nodiscard]] _LIBCPP_HIDE_FROM_ABI static time_point now() { return 
from_sys(system_clock::now()); }
+
+  template 
+  [[nodiscard]] _LIBCPP_HIDE_FROM_ABI static sys_time>
+  to_sys(const utc_time<_Duration>& __time);
+
+  template 
+  [[nodiscard]] _LIBCPP_HIDE_FROM_ABI static utc_time>
+  from_sys(const sys_time<_Duration>& __time) {
+using _Rp = utc_time>;
+// TODO TZDB investigate optimizations.
+//
+// The leap second database stores all transitions, this mean to calculate
+// the current number of leap seconds the code needs to iterate over all
+// leap seconds to accumulate the sum. Then the sum can be used to 
determine
+// the sys_time. Accessing the database involves acquiring a mutex.
+//
+// The historic entries in the database are immutable. Hard-coding these
+// values in a table would allow:
+// - To store the sum, allowing a binary search on the data.
+// - Avoid acquiring a mutex.
+// The disadvantage are:
+// - A slightly larger code size.
+//
+// There are two optimization directions
+// - hard-code the database and do a linear search for future entries. This
+//   search can start at the back, and should probably contain very few
+//   entries. (Adding leap seconds is quite rare and new release of libc++
+//   can add the new entries; they are announced half a year before they 
are
+//   added.)
+// - During parsing the leap seconds store an additional database in the
+//   dylib with the list of the sum of the leap seconds. In that case there
+//   can be a private function __get_utc_to_sys_table that returns the
+//   table.
+//
+// Note for to_sys there are no optimizations to be done; it uses
+// get_leap_second_info. The function get_leap_second_info could benefit
+// from optimizations as described above; again both options apply.
+
+// Both UTC and the system clock use the same epoch. The Standard
+// specifies from 1970-01-01 even when UTC starts at
+// 1972-01-01 00:00:10 TAI. So when the sys_time is before epoch we can be
+// sure there both clocks return the same value.
+
+const tzdb& __tzdb = chrono::get_tzdb();
+_Rp __result{__time.time_since_epoch()};
+for (const auto& __leap_second : __tzdb.leap_seconds) {
+  if (__time < __leap_second)
+return __result;
+
+  __result += __leap_second.value();
+}
+return __result;
+  }
+};
+
+struct leap_second_info {
+  bool is_leap_second;
+  seconds elapsed;
+};
+
+template 
+[[nodiscard]] _LIBCPP_HIDE_FROM_ABI leap_second_info 
get_leap_second_info(const utc_time<_Duration>& __time) {
+  const tzdb& __tzdb = chrono::get_tzdb();
+  if (__tzdb.leap_seconds.empty())
+return {false, chrono::seconds{0}};
+
+  sys_seconds __sys{chrono::floor(__time).time_since_epoch()};
+  seconds __elapsed{0};
+  for (const auto& __leap_second : __tzdb.leap_seconds) {
+if (__sys == __leap_second.date() + __elapsed)
+  return {__leap_second.value() > 0s, // only positive leap seconds are 
considered leap seconds
+  __elapsed + __leap_second.value()};
+
+if (__sys < __leap_second.date() + __elapsed)
+  return {false, __elapsed};
+
+__elapsed += __leap_second.value();
+  }
+
+  return {false, __elapsed};
+}
+
+template 

[llvm-branch-commits] [libcxx] [libc++][TZDB] Implements time_zone::to_sys. (PR #90394)

2024-05-01 Thread Mark de Wever via llvm-branch-commits

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

>From fe9a4ce7f13e981d1ebcdfb088e16da686e22ea1 Mon Sep 17 00:00:00 2001
From: Mark de Wever 
Date: Wed, 17 Apr 2024 21:00:22 +0200
Subject: [PATCH] [libc++][TZDB] Implements time_zone::to_sys.

This implements the throwing overload and the exception classes throw by
this overload.

Implements parts of:
- P0355 Extending chrono to Calendars and Time Zones
---
 libcxx/include/CMakeLists.txt |   1 +
 libcxx/include/__chrono/exception.h   | 129 ++
 libcxx/include/__chrono/time_zone.h   |  26 ++
 libcxx/include/chrono |   9 +
 libcxx/include/module.modulemap   |   6 +-
 libcxx/modules/std/chrono.inc |   2 -
 libcxx/src/CMakeLists.txt |   3 +
 libcxx/src/chrono_exception.cpp   |  20 ++
 .../assert.ctor.pass.cpp  |  53 
 .../assert.ctor.pass.cpp  |  53 
 .../time.zone.members/assert.to_sys.pass.cpp  |  39 +++
 .../test/libcxx/transitive_includes/cxx03.csv |   3 -
 .../test/libcxx/transitive_includes/cxx11.csv |   3 -
 .../test/libcxx/transitive_includes/cxx14.csv |   3 -
 .../test/libcxx/transitive_includes/cxx17.csv |   3 -
 .../test/libcxx/transitive_includes/cxx20.csv |   8 +-
 .../test/libcxx/transitive_includes/cxx23.csv |  12 +-
 .../test/libcxx/transitive_includes/cxx26.csv |  12 +-
 .../time.zone.exception.ambig/ctor.pass.cpp   | 171 +
 .../types.compile.pass.cpp|  32 +++
 .../ctor.pass.cpp | 172 +
 .../types.compile.pass.cpp|  32 +++
 .../time.zone.members/to_sys.pass.cpp | 237 ++
 23 files changed, 985 insertions(+), 44 deletions(-)
 create mode 100644 libcxx/include/__chrono/exception.h
 create mode 100644 libcxx/src/chrono_exception.cpp
 create mode 100644 
libcxx/test/libcxx/time/time.zone/time.zone.exception/time.zone.exception.ambig/assert.ctor.pass.cpp
 create mode 100644 
libcxx/test/libcxx/time/time.zone/time.zone.exception/time.zone.exception.nonexist/assert.ctor.pass.cpp
 create mode 100644 
libcxx/test/libcxx/time/time.zone/time.zone.timezone/time.zone.members/assert.to_sys.pass.cpp
 create mode 100644 
libcxx/test/std/time/time.zone/time.zone.exception/time.zone.exception.ambig/ctor.pass.cpp
 create mode 100644 
libcxx/test/std/time/time.zone/time.zone.exception/time.zone.exception.ambig/types.compile.pass.cpp
 create mode 100644 
libcxx/test/std/time/time.zone/time.zone.exception/time.zone.exception.nonexist/ctor.pass.cpp
 create mode 100644 
libcxx/test/std/time/time.zone/time.zone.exception/time.zone.exception.nonexist/types.compile.pass.cpp
 create mode 100644 
libcxx/test/std/time/time.zone/time.zone.timezone/time.zone.members/to_sys.pass.cpp

diff --git a/libcxx/include/CMakeLists.txt b/libcxx/include/CMakeLists.txt
index 1296c536bc882c..386bd967eed7ab 100644
--- a/libcxx/include/CMakeLists.txt
+++ b/libcxx/include/CMakeLists.txt
@@ -264,6 +264,7 @@ set(files
   __chrono/convert_to_tm.h
   __chrono/day.h
   __chrono/duration.h
+  __chrono/exception.h
   __chrono/file_clock.h
   __chrono/formatter.h
   __chrono/hh_mm_ss.h
diff --git a/libcxx/include/__chrono/exception.h 
b/libcxx/include/__chrono/exception.h
new file mode 100644
index 00..9a7fca74fd369c
--- /dev/null
+++ b/libcxx/include/__chrono/exception.h
@@ -0,0 +1,129 @@
+// -*- 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_EXCEPTION_H
+#define _LIBCPP___CHRONO_EXCEPTION_H
+
+#include 
+// Enable the contents of the header only when libc++ was built with 
experimental features enabled.
+#if !defined(_LIBCPP_HAS_NO_EXPERIMENTAL_TZDB)
+
+#  include <__availability>
+#  include <__chrono/calendar.h>
+#  include <__chrono/local_info.h>
+#  include <__chrono/time_point.h>
+#  include <__config>
+#  include <__verbose_abort>
+#  include 
+#  include 
+#  include 
+
+#  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 nonexistent_local_time : public runtime_error {
+public:
+  template 
+  _LIBCPP_HIDE_FROM_ABI nonexistent_local_time(const local_time<_Duration>& 
__time, const local_info& __info)
+  : runtime_error{__create_message(__time, __info)} {
+// [time.zone.exception.nonexist]/2
+//   Preconditions: i.result == local_info::nonexistent is true.
+// The value of 

[llvm-branch-commits] [libcxx] [libc++][TZDB] Implements time_zone::to_sys. (PR #90394)

2024-04-28 Thread Mark de Wever via llvm-branch-commits

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

>From e0f5f099af76108a1b3de6b2735e084047e029c0 Mon Sep 17 00:00:00 2001
From: Mark de Wever 
Date: Wed, 17 Apr 2024 21:00:22 +0200
Subject: [PATCH] [libc++][TZDB] Implements time_zone::to_sys.

This implements the throwing overload and the exception classes throw by
this overload.

Implements parts of:
- P0355 Extending chrono to Calendars and Time Zones
---
 libcxx/include/CMakeLists.txt |   1 +
 libcxx/include/__chrono/exception.h   | 129 ++
 libcxx/include/__chrono/time_zone.h   |  26 ++
 libcxx/include/chrono |   9 +
 libcxx/include/module.modulemap   |   6 +-
 libcxx/modules/std/chrono.inc |   2 -
 libcxx/src/CMakeLists.txt |   3 +
 libcxx/src/chrono_exception.cpp   |  20 ++
 .../assert.ctor.pass.cpp  |  53 
 .../assert.ctor.pass.cpp  |  53 
 .../time.zone.members/assert.to_sys.pass.cpp  |  39 +++
 .../test/libcxx/transitive_includes/cxx03.csv |   3 -
 .../test/libcxx/transitive_includes/cxx11.csv |   3 -
 .../test/libcxx/transitive_includes/cxx14.csv |   3 -
 .../test/libcxx/transitive_includes/cxx17.csv |   3 -
 .../test/libcxx/transitive_includes/cxx20.csv |   8 +-
 .../test/libcxx/transitive_includes/cxx23.csv |  12 +-
 .../test/libcxx/transitive_includes/cxx26.csv |  12 +-
 .../time.zone.exception.ambig/ctor.pass.cpp   | 171 +
 .../types.compile.pass.cpp|  31 +++
 .../ctor.pass.cpp | 172 +
 .../types.compile.pass.cpp|  31 +++
 .../time.zone.members/to_sys.pass.cpp | 237 ++
 23 files changed, 983 insertions(+), 44 deletions(-)
 create mode 100644 libcxx/include/__chrono/exception.h
 create mode 100644 libcxx/src/chrono_exception.cpp
 create mode 100644 
libcxx/test/libcxx/time/time.zone/time.zone.exception/time.zone.exception.ambig/assert.ctor.pass.cpp
 create mode 100644 
libcxx/test/libcxx/time/time.zone/time.zone.exception/time.zone.exception.nonexist/assert.ctor.pass.cpp
 create mode 100644 
libcxx/test/libcxx/time/time.zone/time.zone.timezone/time.zone.members/assert.to_sys.pass.cpp
 create mode 100644 
libcxx/test/std/time/time.zone/time.zone.exception/time.zone.exception.ambig/ctor.pass.cpp
 create mode 100644 
libcxx/test/std/time/time.zone/time.zone.exception/time.zone.exception.ambig/types.compile.pass.cpp
 create mode 100644 
libcxx/test/std/time/time.zone/time.zone.exception/time.zone.exception.nonexist/ctor.pass.cpp
 create mode 100644 
libcxx/test/std/time/time.zone/time.zone.exception/time.zone.exception.nonexist/types.compile.pass.cpp
 create mode 100644 
libcxx/test/std/time/time.zone/time.zone.timezone/time.zone.members/to_sys.pass.cpp

diff --git a/libcxx/include/CMakeLists.txt b/libcxx/include/CMakeLists.txt
index 1296c536bc882c..386bd967eed7ab 100644
--- a/libcxx/include/CMakeLists.txt
+++ b/libcxx/include/CMakeLists.txt
@@ -264,6 +264,7 @@ set(files
   __chrono/convert_to_tm.h
   __chrono/day.h
   __chrono/duration.h
+  __chrono/exception.h
   __chrono/file_clock.h
   __chrono/formatter.h
   __chrono/hh_mm_ss.h
diff --git a/libcxx/include/__chrono/exception.h 
b/libcxx/include/__chrono/exception.h
new file mode 100644
index 00..fa9e0cf90e5d96
--- /dev/null
+++ b/libcxx/include/__chrono/exception.h
@@ -0,0 +1,129 @@
+// -*- 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_EXCEPTION_H
+#define _LIBCPP___CHRONO_EXCEPTION_H
+
+#include 
+// Enable the contents of the header only when libc++ was built with 
experimental features enabled.
+#if !defined(_LIBCPP_HAS_NO_EXPERIMENTAL_TZDB)
+
+#  include <__availability>
+#  include <__chrono/calendar.h>
+#  include <__chrono/local_info.h>
+#  include <__chrono/time_point.h>
+#  include <__config>
+#  include <__verbose_abort>
+#  include 
+#  include 
+#  include 
+
+#  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 nonexistent_local_time : public runtime_error {
+public:
+  template 
+  _LIBCPP_HIDE_FROM_ABI nonexistent_local_time(const local_time<_Duration>& 
__time, const local_info& __info)
+  : runtime_error{__create_message(__time, __info)} {
+// [time.zone.exception.nonexist]/2
+//   Preconditions: i.result == local_info::nonexistent is true.
+// The value of 

[llvm-branch-commits] [libcxx] [libc++][TZDB] Implements time_zone::to_sys. (PR #90394)

2024-04-28 Thread Mark de Wever via llvm-branch-commits

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

>From c0cdd074a1e22c3d35f2e235cfd6f0bf74b406dc Mon Sep 17 00:00:00 2001
From: Mark de Wever 
Date: Wed, 17 Apr 2024 21:00:22 +0200
Subject: [PATCH] [libc++][TZDB] Implements time_zone::to_sys.

This implements the throwing overload and the exception classes throw by
this overload.

Implements parts of:
- P0355 Extending chrono to Calendars and Time Zones
---
 libcxx/include/CMakeLists.txt |   1 +
 libcxx/include/__chrono/exception.h   | 129 ++
 libcxx/include/__chrono/time_zone.h   |  26 ++
 libcxx/include/chrono |   9 +
 libcxx/include/module.modulemap   |   6 +-
 libcxx/modules/std/chrono.inc |   2 -
 libcxx/src/CMakeLists.txt |   3 +
 libcxx/src/chrono_exception.cpp   |  20 ++
 .../assert.ctor.pass.cpp  |  53 
 .../assert.ctor.pass.cpp  |  53 
 .../time.zone.members/assert.to_sys.pass.cpp  |  39 +++
 .../test/libcxx/transitive_includes/cxx03.csv |   3 -
 .../test/libcxx/transitive_includes/cxx11.csv |   3 -
 .../test/libcxx/transitive_includes/cxx14.csv |   3 -
 .../test/libcxx/transitive_includes/cxx17.csv |   3 -
 .../test/libcxx/transitive_includes/cxx20.csv |   8 +-
 .../test/libcxx/transitive_includes/cxx23.csv |  12 +-
 .../test/libcxx/transitive_includes/cxx26.csv |  12 +-
 .../time.zone.exception.ambig/ctor.pass.cpp   | 169 +
 .../types.compile.pass.cpp|  31 +++
 .../ctor.pass.cpp | 170 +
 .../types.compile.pass.cpp|  31 +++
 .../time.zone.members/to_sys.pass.cpp | 237 ++
 23 files changed, 979 insertions(+), 44 deletions(-)
 create mode 100644 libcxx/include/__chrono/exception.h
 create mode 100644 libcxx/src/chrono_exception.cpp
 create mode 100644 
libcxx/test/libcxx/time/time.zone/time.zone.exception/time.zone.exception.ambig/assert.ctor.pass.cpp
 create mode 100644 
libcxx/test/libcxx/time/time.zone/time.zone.exception/time.zone.exception.nonexist/assert.ctor.pass.cpp
 create mode 100644 
libcxx/test/libcxx/time/time.zone/time.zone.timezone/time.zone.members/assert.to_sys.pass.cpp
 create mode 100644 
libcxx/test/std/time/time.zone/time.zone.exception/time.zone.exception.ambig/ctor.pass.cpp
 create mode 100644 
libcxx/test/std/time/time.zone/time.zone.exception/time.zone.exception.ambig/types.compile.pass.cpp
 create mode 100644 
libcxx/test/std/time/time.zone/time.zone.exception/time.zone.exception.nonexist/ctor.pass.cpp
 create mode 100644 
libcxx/test/std/time/time.zone/time.zone.exception/time.zone.exception.nonexist/types.compile.pass.cpp
 create mode 100644 
libcxx/test/std/time/time.zone/time.zone.timezone/time.zone.members/to_sys.pass.cpp

diff --git a/libcxx/include/CMakeLists.txt b/libcxx/include/CMakeLists.txt
index 1296c536bc882c..386bd967eed7ab 100644
--- a/libcxx/include/CMakeLists.txt
+++ b/libcxx/include/CMakeLists.txt
@@ -264,6 +264,7 @@ set(files
   __chrono/convert_to_tm.h
   __chrono/day.h
   __chrono/duration.h
+  __chrono/exception.h
   __chrono/file_clock.h
   __chrono/formatter.h
   __chrono/hh_mm_ss.h
diff --git a/libcxx/include/__chrono/exception.h 
b/libcxx/include/__chrono/exception.h
new file mode 100644
index 00..fa9e0cf90e5d96
--- /dev/null
+++ b/libcxx/include/__chrono/exception.h
@@ -0,0 +1,129 @@
+// -*- 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_EXCEPTION_H
+#define _LIBCPP___CHRONO_EXCEPTION_H
+
+#include 
+// Enable the contents of the header only when libc++ was built with 
experimental features enabled.
+#if !defined(_LIBCPP_HAS_NO_EXPERIMENTAL_TZDB)
+
+#  include <__availability>
+#  include <__chrono/calendar.h>
+#  include <__chrono/local_info.h>
+#  include <__chrono/time_point.h>
+#  include <__config>
+#  include <__verbose_abort>
+#  include 
+#  include 
+#  include 
+
+#  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 nonexistent_local_time : public runtime_error {
+public:
+  template 
+  _LIBCPP_HIDE_FROM_ABI nonexistent_local_time(const local_time<_Duration>& 
__time, const local_info& __info)
+  : runtime_error{__create_message(__time, __info)} {
+// [time.zone.exception.nonexist]/2
+//   Preconditions: i.result == local_info::nonexistent is true.
+// The value of 

[llvm-branch-commits] [libcxx] [libc++][TZDB] Implements time_zone::to_sys. (PR #90394)

2024-04-28 Thread Mark de Wever via llvm-branch-commits

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

This implements the throwing overload and the exception classes throw by this 
overload.

Implements parts of:
- P0355 Extending chrono to Calendars and Time Zones

>From e722747d35b87cbcf8e12847c799f87a6082bb73 Mon Sep 17 00:00:00 2001
From: Mark de Wever 
Date: Wed, 17 Apr 2024 21:00:22 +0200
Subject: [PATCH] [libc++][TZDB] Implements time_zone::to_sys.

This implements the throwing overload and the exception classes throw by
this overload.

Implements parts of:
- P0355 Extending chrono to Calendars and Time Zones
---
 libcxx/include/CMakeLists.txt |   1 +
 libcxx/include/__chrono/exception.h   | 128 ++
 libcxx/include/__chrono/time_zone.h   |  25 ++
 libcxx/include/chrono |   9 +
 libcxx/include/module.modulemap   |   1 +
 libcxx/modules/std/chrono.inc |   2 -
 libcxx/src/CMakeLists.txt |   3 +
 libcxx/src/chrono_exception.cpp   |  20 ++
 .../assert.ctor.pass.cpp  |  53 
 .../assert.ctor.pass.cpp  |  53 
 .../time.zone.members/assert.to_sys.pass.cpp  |  39 +++
 .../time.zone.exception.ambig/ctor.pass.cpp   | 169 +
 .../types.compile.pass.cpp|  31 +++
 .../ctor.pass.cpp | 170 +
 .../types.compile.pass.cpp|  31 +++
 .../time.zone.members/to_sys.pass.cpp | 237 ++
 16 files changed, 970 insertions(+), 2 deletions(-)
 create mode 100644 libcxx/include/__chrono/exception.h
 create mode 100644 libcxx/src/chrono_exception.cpp
 create mode 100644 
libcxx/test/libcxx/time/time.zone/time.zone.exception/time.zone.exception.ambig/assert.ctor.pass.cpp
 create mode 100644 
libcxx/test/libcxx/time/time.zone/time.zone.exception/time.zone.exception.nonexist/assert.ctor.pass.cpp
 create mode 100644 
libcxx/test/libcxx/time/time.zone/time.zone.timezone/time.zone.members/assert.to_sys.pass.cpp
 create mode 100644 
libcxx/test/std/time/time.zone/time.zone.exception/time.zone.exception.ambig/ctor.pass.cpp
 create mode 100644 
libcxx/test/std/time/time.zone/time.zone.exception/time.zone.exception.ambig/types.compile.pass.cpp
 create mode 100644 
libcxx/test/std/time/time.zone/time.zone.exception/time.zone.exception.nonexist/ctor.pass.cpp
 create mode 100644 
libcxx/test/std/time/time.zone/time.zone.exception/time.zone.exception.nonexist/types.compile.pass.cpp
 create mode 100644 
libcxx/test/std/time/time.zone/time.zone.timezone/time.zone.members/to_sys.pass.cpp

diff --git a/libcxx/include/CMakeLists.txt b/libcxx/include/CMakeLists.txt
index 1296c536bc882c..386bd967eed7ab 100644
--- a/libcxx/include/CMakeLists.txt
+++ b/libcxx/include/CMakeLists.txt
@@ -264,6 +264,7 @@ set(files
   __chrono/convert_to_tm.h
   __chrono/day.h
   __chrono/duration.h
+  __chrono/exception.h
   __chrono/file_clock.h
   __chrono/formatter.h
   __chrono/hh_mm_ss.h
diff --git a/libcxx/include/__chrono/exception.h 
b/libcxx/include/__chrono/exception.h
new file mode 100644
index 00..ca0acecf151ba9
--- /dev/null
+++ b/libcxx/include/__chrono/exception.h
@@ -0,0 +1,128 @@
+// -*- 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_EXCEPTION_H
+#define _LIBCPP___CHRONO_EXCEPTION_H
+
+#include 
+// Enable the contents of the header only when libc++ was built with 
experimental features enabled.
+#if !defined(_LIBCPP_HAS_NO_EXPERIMENTAL_TZDB)
+
+#  include <__availability>
+#  include <__chrono/calendar.h>
+#  include <__chrono/local_info.h>
+#  include <__config>
+#  include <__verbose_abort>
+#  include 
+#  include 
+#  include 
+
+#  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 nonexistent_local_time : public runtime_error {
+public:
+  template 
+  _LIBCPP_HIDE_FROM_ABI nonexistent_local_time(const local_time<_Duration>& 
__time, const local_info& __info)
+  : runtime_error{__create_message(__time, __info)} {
+// [time.zone.exception.nonexist]/2
+//   Preconditions: i.result == local_info::nonexistent is true.
+// The value of __info.result is not used.
+_LIBCPP_ASSERT_PEDANTIC(__info.result == local_info::nonexistent,
+"creating an nonexistent_local_time from a 
local_info that is not non-existent");
+  }
+
+  _LIBCPP_AVAILABILITY_TZDB 

[llvm-branch-commits] [libcxx] [libc++][chrono] Fixes leap seconds. (PR #90070)

2024-04-25 Thread Mark de Wever via llvm-branch-commits

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

While implementing the UTC clock it turns out that the implementation of the 
leap seconds was not correct, it should store the individual value, not the sum.

It also looks like LWG3359 has not been fully implemented.

Implements parts of:
- LWG3359  leap second support should allow for negative leap seconds

>From d094cded6d023bbffdca0af983ef64e00289c797 Mon Sep 17 00:00:00 2001
From: Mark de Wever 
Date: Mon, 15 Apr 2024 19:56:40 +0200
Subject: [PATCH] [libc++][chrono] Fixes leap seconds.

While implementing the UTC clock it turns out that the implementation of
the leap seconds was not correct, it should store the individual value,
not the sum.

It also looks like LWG3359 has not been fully implemented.

Implements parts of:
- LWG3359  leap second support should allow for negative leap seconds
---
 libcxx/docs/Status/Cxx20Issues.csv|  2 +-
 libcxx/src/tzdb.cpp   | 64 ---
 .../time.zone.db/leap_seconds.pass.cpp| 23 ---
 .../time.zone.db/leap_seconds.pass.cpp| 55 
 4 files changed, 83 insertions(+), 61 deletions(-)

diff --git a/libcxx/docs/Status/Cxx20Issues.csv 
b/libcxx/docs/Status/Cxx20Issues.csv
index db57b15256a62f..fed1c7e736248f 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","|Complete|","19.0","|chrono|"
+"`3359 `__","\  leap second support 
should allow for negative leap seconds","Prague","|In Progress|","","|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|"
diff --git a/libcxx/src/tzdb.cpp b/libcxx/src/tzdb.cpp
index 5951e59248e94f..8588646bbbc417 100644
--- a/libcxx/src/tzdb.cpp
+++ b/libcxx/src/tzdb.cpp
@@ -626,29 +626,49 @@ static void __parse_leap_seconds(vector& 
__leap_seconds, istream&&
   // seconds since 1 January 1970.
   constexpr auto __offset = sys_days{1970y / January / 1} - sys_days{1900y / 
January / 1};
 
-  while (true) {
-switch (__input.peek()) {
-case istream::traits_type::eof():
-  return;
-
-case ' ':
-case '\t':
-case '\n':
-  __input.get();
-  continue;
+  struct __entry {
+sys_seconds __timestamp;
+seconds __value;
+  };
+  vector<__entry> __entries;
+  [&] {
+while (true) {
+  switch (__input.peek()) {
+  case istream::traits_type::eof():
+return;
+
+  case ' ':
+  case '\t':
+  case '\n':
+__input.get();
+continue;
+
+  case '#':
+chrono::__skip_line(__input);
+continue;
+  }
 
-case '#':
+  sys_seconds __date = 
sys_seconds{seconds{chrono::__parse_integral(__input, false)}} - __offset;
+  chrono::__skip_mandatory_whitespace(__input);
+  seconds __value{chrono::__parse_integral(__input, false)};
   chrono::__skip_line(__input);
-  continue;
-}
 
-sys_seconds __date = sys_seconds{seconds{chrono::__parse_integral(__input, 
false)}} - __offset;
-chrono::__skip_mandatory_whitespace(__input);
-seconds __value{chrono::__parse_integral(__input, false)};
-chrono::__skip_line(__input);
-
-__leap_seconds.emplace_back(std::__private_constructor_tag{}, __date, 
__value);
-  }
+  __entries.emplace_back(__date, __value);
+}
+  }();
+  // The Standard requires the leap seconds to be sorted. The file
+  // leap-seconds.list usually provides them in sorted order, but that is not
+  // guaranteed so we ensure it here.
+  std::ranges::sort(__entries, {}, &__entry::__timestamp);
+
+  // The database should contain the number of seconds inserted by a leap
+  // second (1 or -1). So the difference between the two elements are stored.
+  // std::ranges::views::adjacent has not been implemented yet.
+  (void)ranges::adjacent_find(__entries, [&](const __entry& __first, const 
__entry& __second) {
+__leap_seconds.emplace_back(
+std::__private_constructor_tag{}, __second.__timestamp, 
__second.__value - __first.__value);
+return 

[llvm-branch-commits] [libcxx] release/18.x: [libcxx] [modules] Add _LIBCPP_USING_IF_EXISTS on aligned_alloc (#89827) (PR #89894)

2024-04-24 Thread Mark de Wever via llvm-branch-commits

https://github.com/mordante approved this pull request.


https://github.com/llvm/llvm-project/pull/89894
___
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++] Makes saturation functions privately available. (PR #89503)

2024-04-23 Thread Mark de Wever via llvm-branch-commits

mordante wrote:

> @mordante The PR looks odd. Is this intentional or have you mixed two 
> branches?

This is due to using manually stacked reviews in GitHub. This is patch 3 in a 
series
* patch 1 has landed
* I just rebased patch 2 and wait for the CI
* patch 3 now believes patches 1 & 2 part of this branch. This will be fixed 
after I rebase this patch on the new patch 2

I really miss the nice stacked reviews of Phabriacator.

https://github.com/llvm/llvm-project/pull/89503
___
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++][TZDB] Implements time zone get_info(local_time). (PR #89537)

2024-04-21 Thread Mark de Wever via llvm-branch-commits

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

Implements parts of:
- P0355 Extending to Calendars and Time Zones

>From ed7053e22620924b6bc18a46cfd6d7201afab3fe Mon Sep 17 00:00:00 2001
From: Mark de Wever 
Date: Wed, 17 Apr 2024 21:00:22 +0200
Subject: [PATCH] [libc++][TZDB] Implements time zone get_info(local_time).

Implements parts of:
- P0355 Extending to Calendars and Time Zones
---
 libcxx/include/__chrono/time_zone.h   |7 +
 libcxx/include/chrono |3 +
 libcxx/src/time_zone.cpp  |  175 +++
 .../chrono.nodiscard_extensions.verify.cpp|2 +
 .../get_info.local_time.pass.cpp  | 1302 +
 5 files changed, 1489 insertions(+)
 create mode 100644 
libcxx/test/std/time/time.zone/time.zone.timezone/time.zone.members/get_info.local_time.pass.cpp

diff --git a/libcxx/include/__chrono/time_zone.h 
b/libcxx/include/__chrono/time_zone.h
index 799602c1cdbaf0..3ea03683ccc187 100644
--- a/libcxx/include/__chrono/time_zone.h
+++ b/libcxx/include/__chrono/time_zone.h
@@ -17,6 +17,7 @@
 #if !defined(_LIBCPP_HAS_NO_EXPERIMENTAL_TZDB)
 
 #  include <__chrono/duration.h>
+#  include <__chrono/local_info.h>
 #  include <__chrono/sys_info.h>
 #  include <__chrono/system_clock.h>
 #  include <__compare/strong_order.h>
@@ -63,12 +64,18 @@ class _LIBCPP_AVAILABILITY_TZDB time_zone {
 return __get_info(chrono::time_point_cast(__time));
   }
 
+  template 
+  [[nodiscard]] _LIBCPP_HIDE_FROM_ABI local_info get_info(const 
local_time<_Duration>& __time) const {
+return __get_info(chrono::time_point_cast(__time));
+  }
+
   [[nodiscard]] _LIBCPP_HIDE_FROM_ABI const __impl& __implementation() const 
noexcept { return *__impl_; }
 
 private:
   [[nodiscard]] _LIBCPP_EXPORTED_FROM_ABI string_view __name() const noexcept;
 
   [[nodiscard]] _LIBCPP_AVAILABILITY_TZDB _LIBCPP_EXPORTED_FROM_ABI sys_info 
__get_info(sys_seconds __time) const;
+  [[nodiscard]] _LIBCPP_AVAILABILITY_TZDB _LIBCPP_EXPORTED_FROM_ABI local_info 
__get_info(local_seconds __time) const;
 
   unique_ptr<__impl> __impl_;
 };
diff --git a/libcxx/include/chrono b/libcxx/include/chrono
index 96a3e92faa81f2..4d8398af1a108f 100644
--- a/libcxx/include/chrono
+++ b/libcxx/include/chrono
@@ -763,6 +763,9 @@ class time_zone {
 
   template
   sys_info get_info(const sys_time& st) const;
+
+  template
+  local_info get_info(const local_time& tp) const;
 };
 bool operator==(const time_zone& x, const time_zone& y) noexcept;  
  // C++20
 strong_ordering operator<=>(const time_zone& x, const time_zone& y) noexcept;  
  // C++20
diff --git a/libcxx/src/time_zone.cpp b/libcxx/src/time_zone.cpp
index 928f3d2855e456..24c22859080e10 100644
--- a/libcxx/src/time_zone.cpp
+++ b/libcxx/src/time_zone.cpp
@@ -34,6 +34,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 
 #include "include/tzdb/time_zone_private.h"
@@ -903,6 +904,180 @@ time_zone::__get_info(sys_seconds __time) const {
   std::__throw_runtime_error("tzdb: corrupt db");
 }
 
+enum class __position {
+  __beginning,
+  __middle,
+  __end,
+};
+
+// Determines the position of "__time" inside "__info".
+//
+// The code picks an arbitrary value to determine the "middle"
+// - Every time that is more than the threshold from a boundary, or
+// - Every value that is at the boundary sys_seconds::min() or
+//   sys_seconds::max().
+//
+// If not in the middle, it returns __beginning or __end.
+[[nodiscard]] static __position __get_position(sys_seconds __time, const 
sys_info __info) {
+  _LIBCPP_ASSERT_ARGUMENT_WITHIN_DOMAIN(
+  __time >= __info.begin && __time < __info.end, "A value outside the 
range's position can't be determined.");
+
+  using _Tp = sys_seconds::rep;
+  // Africa/Freetown has a 4 day "zone"
+  // Africa/Freetown  Fri Sep  1 00:59:59 1939 UT = Thu Aug 31 23:59:59 1939 
-01 isdst=0 gmtoff=-3600
+  // Africa/Freetown  Fri Sep  1 01:00:00 1939 UT = Fri Sep  1 00:20:00 1939 
-0040 isdst=1 gmtoff=-2400
+  // Africa/Freetown  Tue Sep  5 00:39:59 1939 UT = Mon Sep  4 23:59:59 1939 
-0040 isdst=1 gmtoff=-2400
+  // Africa/Freetown  Tue Sep  5 00:40:00 1939 UT = Mon Sep  4 23:40:00 1939 
-01 isdst=0 gmtoff=-3600
+  //
+  // Originally used a one week threshold, but due to this switched to 1 day.
+  // This seems to work in practice.
+  //
+  // TODO TZDB Evaluate the proper threshold.
+  constexpr _Tp __threshold = 24 * 3600;
+
+  _Tp __upper = std::__add_sat(__info.begin.time_since_epoch().count(), 
__threshold);
+  if (__time >= __info.begin && __time.time_since_epoch().count() < __upper)
+return __info.begin != sys_seconds::min() ? __position::__beginning : 
__position::__middle;
+
+  _Tp __lower = std::__sub_sat(__info.end.time_since_epoch().count(), 
__threshold);
+  if (__time < __info.end && __time.time_since_epoch().count() >= __lower)
+return __info.end != sys_seconds::max() ? __position::__end : 
__position::__middle;
+
+  return 

[llvm-branch-commits] [libcxx] [libc++] Makes saturation functions privately available. (PR #89503)

2024-04-20 Thread Mark de Wever via llvm-branch-commits

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

>From d1f131136d005699a882bf30af9520b06fc898b4 Mon Sep 17 00:00:00 2001
From: Mark de Wever 
Date: Wed, 17 Apr 2024 21:00:22 +0200
Subject: [PATCH 1/3] [libc++] Makes saturation functions privately available.

These functions are useful in the implementation of the time zone
database. So expose them with private names.

The functions could be exposed before C++ 20, but since libc++ is mostly
C++ 17 complete it seems less useful to allow earlier.
---
 .../include/__numeric/saturation_arithmetic.h | 41 ---
 1 file changed, 35 insertions(+), 6 deletions(-)

diff --git a/libcxx/include/__numeric/saturation_arithmetic.h 
b/libcxx/include/__numeric/saturation_arithmetic.h
index 41596a0c58e27d..fd64cac935de85 100644
--- a/libcxx/include/__numeric/saturation_arithmetic.h
+++ b/libcxx/include/__numeric/saturation_arithmetic.h
@@ -25,10 +25,10 @@ _LIBCPP_PUSH_MACROS
 
 _LIBCPP_BEGIN_NAMESPACE_STD
 
-#if _LIBCPP_STD_VER >= 26
+#if _LIBCPP_STD_VER >= 20
 
 template <__libcpp_integer _Tp>
-_LIBCPP_HIDE_FROM_ABI constexpr _Tp add_sat(_Tp __x, _Tp __y) noexcept {
+_LIBCPP_HIDE_FROM_ABI constexpr _Tp __add_sat(_Tp __x, _Tp __y) noexcept {
   if (_Tp __sum; !__builtin_add_overflow(__x, __y, &__sum))
 return __sum;
   // Handle overflow
@@ -46,7 +46,7 @@ _LIBCPP_HIDE_FROM_ABI constexpr _Tp add_sat(_Tp __x, _Tp __y) 
noexcept {
 }
 
 template <__libcpp_integer _Tp>
-_LIBCPP_HIDE_FROM_ABI constexpr _Tp sub_sat(_Tp __x, _Tp __y) noexcept {
+_LIBCPP_HIDE_FROM_ABI constexpr _Tp __sub_sat(_Tp __x, _Tp __y) noexcept {
   if (_Tp __sub; !__builtin_sub_overflow(__x, __y, &__sub))
 return __sub;
   // Handle overflow
@@ -65,7 +65,7 @@ _LIBCPP_HIDE_FROM_ABI constexpr _Tp sub_sat(_Tp __x, _Tp __y) 
noexcept {
 }
 
 template <__libcpp_integer _Tp>
-_LIBCPP_HIDE_FROM_ABI constexpr _Tp mul_sat(_Tp __x, _Tp __y) noexcept {
+_LIBCPP_HIDE_FROM_ABI constexpr _Tp __mul_sat(_Tp __x, _Tp __y) noexcept {
   if (_Tp __mul; !__builtin_mul_overflow(__x, __y, &__mul))
 return __mul;
   // Handle overflow
@@ -81,7 +81,7 @@ _LIBCPP_HIDE_FROM_ABI constexpr _Tp mul_sat(_Tp __x, _Tp __y) 
noexcept {
 }
 
 template <__libcpp_integer _Tp>
-_LIBCPP_HIDE_FROM_ABI constexpr _Tp div_sat(_Tp __x, _Tp __y) noexcept {
+_LIBCPP_HIDE_FROM_ABI constexpr _Tp __div_sat(_Tp __x, _Tp __y) noexcept {
   _LIBCPP_ASSERT_UNCATEGORIZED(__y != 0, "Division by 0 is undefined");
   if constexpr (__libcpp_unsigned_integer<_Tp>) {
 return __x / __y;
@@ -94,7 +94,7 @@ _LIBCPP_HIDE_FROM_ABI constexpr _Tp div_sat(_Tp __x, _Tp __y) 
noexcept {
 }
 
 template <__libcpp_integer _Rp, __libcpp_integer _Tp>
-_LIBCPP_HIDE_FROM_ABI constexpr _Rp saturate_cast(_Tp __x) noexcept {
+_LIBCPP_HIDE_FROM_ABI constexpr _Rp __saturate_cast(_Tp __x) noexcept {
   // Saturation is impossible edge case when ((min _Rp) < (min _Tp) && (max 
_Rp) > (max _Tp)) and it is expected to be
   // optimized out by the compiler.
 
@@ -107,6 +107,35 @@ _LIBCPP_HIDE_FROM_ABI constexpr _Rp saturate_cast(_Tp __x) 
noexcept {
   return static_cast<_Rp>(__x);
 }
 
+#endif // _LIBCPP_STD_VER >= 20
+
+#if _LIBCPP_STD_VER >= 26
+
+template <__libcpp_integer _Tp>
+_LIBCPP_HIDE_FROM_ABI constexpr _Tp add_sat(_Tp __x, _Tp __y) noexcept {
+  return std::add_sat(__x, __y);
+}
+
+template <__libcpp_integer _Tp>
+_LIBCPP_HIDE_FROM_ABI constexpr _Tp sub_sat(_Tp __x, _Tp __y) noexcept {
+  return std::sub_sat(__x, __y);
+}
+
+template <__libcpp_integer _Tp>
+_LIBCPP_HIDE_FROM_ABI constexpr _Tp mul_sat(_Tp __x, _Tp __y) noexcept {
+  return std::mul_sat(__x, __y);
+}
+
+template <__libcpp_integer _Tp>
+_LIBCPP_HIDE_FROM_ABI constexpr _Tp div_sat(_Tp __x, _Tp __y) noexcept {
+  return std::div_sat(__x, __y);
+}
+
+template <__libcpp_integer _Rp, __libcpp_integer _Tp>
+_LIBCPP_HIDE_FROM_ABI constexpr _Rp saturate_cast(_Tp __x) noexcept {
+  return std::saturate_cast<_Rp>(__x);
+}
+
 #endif // _LIBCPP_STD_VER >= 26
 
 _LIBCPP_END_NAMESPACE_STD

>From 84f547d0da8721c105dea5faa9ed7eedd1e19d61 Mon Sep 17 00:00:00 2001
From: Mark de Wever 
Date: Sat, 20 Apr 2024 18:35:24 +0200
Subject: [PATCH 2/3] Update libcxx/include/__numeric/saturation_arithmetic.h

Co-authored-by: Hristo Hristov 
---
 libcxx/include/__numeric/saturation_arithmetic.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libcxx/include/__numeric/saturation_arithmetic.h 
b/libcxx/include/__numeric/saturation_arithmetic.h
index fd64cac935de85..d6c02ac224f9e2 100644
--- a/libcxx/include/__numeric/saturation_arithmetic.h
+++ b/libcxx/include/__numeric/saturation_arithmetic.h
@@ -113,7 +113,7 @@ _LIBCPP_HIDE_FROM_ABI constexpr _Rp __saturate_cast(_Tp 
__x) noexcept {
 
 template <__libcpp_integer _Tp>
 _LIBCPP_HIDE_FROM_ABI constexpr _Tp add_sat(_Tp __x, _Tp __y) noexcept {
-  return std::add_sat(__x, __y);
+  return std::__add_sat(__x, __y);
 }
 
 template <__libcpp_integer _Tp>

>From 483890963a0ae405f4822b6546a3f8a096675191 Mon Sep 17 

[llvm-branch-commits] [libcxx] [libc++] Makes saturation functions privately available. (PR #89503)

2024-04-20 Thread Mark de Wever via llvm-branch-commits

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

>From d1f131136d005699a882bf30af9520b06fc898b4 Mon Sep 17 00:00:00 2001
From: Mark de Wever 
Date: Wed, 17 Apr 2024 21:00:22 +0200
Subject: [PATCH 1/2] [libc++] Makes saturation functions privately available.

These functions are useful in the implementation of the time zone
database. So expose them with private names.

The functions could be exposed before C++ 20, but since libc++ is mostly
C++ 17 complete it seems less useful to allow earlier.
---
 .../include/__numeric/saturation_arithmetic.h | 41 ---
 1 file changed, 35 insertions(+), 6 deletions(-)

diff --git a/libcxx/include/__numeric/saturation_arithmetic.h 
b/libcxx/include/__numeric/saturation_arithmetic.h
index 41596a0c58e27d..fd64cac935de85 100644
--- a/libcxx/include/__numeric/saturation_arithmetic.h
+++ b/libcxx/include/__numeric/saturation_arithmetic.h
@@ -25,10 +25,10 @@ _LIBCPP_PUSH_MACROS
 
 _LIBCPP_BEGIN_NAMESPACE_STD
 
-#if _LIBCPP_STD_VER >= 26
+#if _LIBCPP_STD_VER >= 20
 
 template <__libcpp_integer _Tp>
-_LIBCPP_HIDE_FROM_ABI constexpr _Tp add_sat(_Tp __x, _Tp __y) noexcept {
+_LIBCPP_HIDE_FROM_ABI constexpr _Tp __add_sat(_Tp __x, _Tp __y) noexcept {
   if (_Tp __sum; !__builtin_add_overflow(__x, __y, &__sum))
 return __sum;
   // Handle overflow
@@ -46,7 +46,7 @@ _LIBCPP_HIDE_FROM_ABI constexpr _Tp add_sat(_Tp __x, _Tp __y) 
noexcept {
 }
 
 template <__libcpp_integer _Tp>
-_LIBCPP_HIDE_FROM_ABI constexpr _Tp sub_sat(_Tp __x, _Tp __y) noexcept {
+_LIBCPP_HIDE_FROM_ABI constexpr _Tp __sub_sat(_Tp __x, _Tp __y) noexcept {
   if (_Tp __sub; !__builtin_sub_overflow(__x, __y, &__sub))
 return __sub;
   // Handle overflow
@@ -65,7 +65,7 @@ _LIBCPP_HIDE_FROM_ABI constexpr _Tp sub_sat(_Tp __x, _Tp __y) 
noexcept {
 }
 
 template <__libcpp_integer _Tp>
-_LIBCPP_HIDE_FROM_ABI constexpr _Tp mul_sat(_Tp __x, _Tp __y) noexcept {
+_LIBCPP_HIDE_FROM_ABI constexpr _Tp __mul_sat(_Tp __x, _Tp __y) noexcept {
   if (_Tp __mul; !__builtin_mul_overflow(__x, __y, &__mul))
 return __mul;
   // Handle overflow
@@ -81,7 +81,7 @@ _LIBCPP_HIDE_FROM_ABI constexpr _Tp mul_sat(_Tp __x, _Tp __y) 
noexcept {
 }
 
 template <__libcpp_integer _Tp>
-_LIBCPP_HIDE_FROM_ABI constexpr _Tp div_sat(_Tp __x, _Tp __y) noexcept {
+_LIBCPP_HIDE_FROM_ABI constexpr _Tp __div_sat(_Tp __x, _Tp __y) noexcept {
   _LIBCPP_ASSERT_UNCATEGORIZED(__y != 0, "Division by 0 is undefined");
   if constexpr (__libcpp_unsigned_integer<_Tp>) {
 return __x / __y;
@@ -94,7 +94,7 @@ _LIBCPP_HIDE_FROM_ABI constexpr _Tp div_sat(_Tp __x, _Tp __y) 
noexcept {
 }
 
 template <__libcpp_integer _Rp, __libcpp_integer _Tp>
-_LIBCPP_HIDE_FROM_ABI constexpr _Rp saturate_cast(_Tp __x) noexcept {
+_LIBCPP_HIDE_FROM_ABI constexpr _Rp __saturate_cast(_Tp __x) noexcept {
   // Saturation is impossible edge case when ((min _Rp) < (min _Tp) && (max 
_Rp) > (max _Tp)) and it is expected to be
   // optimized out by the compiler.
 
@@ -107,6 +107,35 @@ _LIBCPP_HIDE_FROM_ABI constexpr _Rp saturate_cast(_Tp __x) 
noexcept {
   return static_cast<_Rp>(__x);
 }
 
+#endif // _LIBCPP_STD_VER >= 20
+
+#if _LIBCPP_STD_VER >= 26
+
+template <__libcpp_integer _Tp>
+_LIBCPP_HIDE_FROM_ABI constexpr _Tp add_sat(_Tp __x, _Tp __y) noexcept {
+  return std::add_sat(__x, __y);
+}
+
+template <__libcpp_integer _Tp>
+_LIBCPP_HIDE_FROM_ABI constexpr _Tp sub_sat(_Tp __x, _Tp __y) noexcept {
+  return std::sub_sat(__x, __y);
+}
+
+template <__libcpp_integer _Tp>
+_LIBCPP_HIDE_FROM_ABI constexpr _Tp mul_sat(_Tp __x, _Tp __y) noexcept {
+  return std::mul_sat(__x, __y);
+}
+
+template <__libcpp_integer _Tp>
+_LIBCPP_HIDE_FROM_ABI constexpr _Tp div_sat(_Tp __x, _Tp __y) noexcept {
+  return std::div_sat(__x, __y);
+}
+
+template <__libcpp_integer _Rp, __libcpp_integer _Tp>
+_LIBCPP_HIDE_FROM_ABI constexpr _Rp saturate_cast(_Tp __x) noexcept {
+  return std::saturate_cast<_Rp>(__x);
+}
+
 #endif // _LIBCPP_STD_VER >= 26
 
 _LIBCPP_END_NAMESPACE_STD

>From 84f547d0da8721c105dea5faa9ed7eedd1e19d61 Mon Sep 17 00:00:00 2001
From: Mark de Wever 
Date: Sat, 20 Apr 2024 18:35:24 +0200
Subject: [PATCH 2/2] Update libcxx/include/__numeric/saturation_arithmetic.h

Co-authored-by: Hristo Hristov 
---
 libcxx/include/__numeric/saturation_arithmetic.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libcxx/include/__numeric/saturation_arithmetic.h 
b/libcxx/include/__numeric/saturation_arithmetic.h
index fd64cac935de85..d6c02ac224f9e2 100644
--- a/libcxx/include/__numeric/saturation_arithmetic.h
+++ b/libcxx/include/__numeric/saturation_arithmetic.h
@@ -113,7 +113,7 @@ _LIBCPP_HIDE_FROM_ABI constexpr _Rp __saturate_cast(_Tp 
__x) noexcept {
 
 template <__libcpp_integer _Tp>
 _LIBCPP_HIDE_FROM_ABI constexpr _Tp add_sat(_Tp __x, _Tp __y) noexcept {
-  return std::add_sat(__x, __y);
+  return std::__add_sat(__x, __y);
 }
 
 template <__libcpp_integer _Tp>

___

[llvm-branch-commits] [libcxx] [libc++] Makes saturation functions privately available. (PR #89503)

2024-04-20 Thread Mark de Wever via llvm-branch-commits


@@ -107,6 +107,35 @@ _LIBCPP_HIDE_FROM_ABI constexpr _Rp saturate_cast(_Tp __x) 
noexcept {
   return static_cast<_Rp>(__x);
 }
 
+#endif // _LIBCPP_STD_VER >= 20
+
+#if _LIBCPP_STD_VER >= 26
+
+template <__libcpp_integer _Tp>
+_LIBCPP_HIDE_FROM_ABI constexpr _Tp add_sat(_Tp __x, _Tp __y) noexcept {
+  return std::add_sat(__x, __y);

mordante wrote:

Thanks good catch!

https://github.com/llvm/llvm-project/pull/89503
___
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++] Makes saturation functions privately available. (PR #89503)

2024-04-20 Thread Mark de Wever via llvm-branch-commits

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

These functions are useful in the implementation of the time zone database. So 
expose them with private names.

The functions could be exposed before C++ 20, but since libc++ is mostly C++ 17 
complete it seems less useful to allow earlier.

>From d1f131136d005699a882bf30af9520b06fc898b4 Mon Sep 17 00:00:00 2001
From: Mark de Wever 
Date: Wed, 17 Apr 2024 21:00:22 +0200
Subject: [PATCH] [libc++] Makes saturation functions privately available.

These functions are useful in the implementation of the time zone
database. So expose them with private names.

The functions could be exposed before C++ 20, but since libc++ is mostly
C++ 17 complete it seems less useful to allow earlier.
---
 .../include/__numeric/saturation_arithmetic.h | 41 ---
 1 file changed, 35 insertions(+), 6 deletions(-)

diff --git a/libcxx/include/__numeric/saturation_arithmetic.h 
b/libcxx/include/__numeric/saturation_arithmetic.h
index 41596a0c58e27d..fd64cac935de85 100644
--- a/libcxx/include/__numeric/saturation_arithmetic.h
+++ b/libcxx/include/__numeric/saturation_arithmetic.h
@@ -25,10 +25,10 @@ _LIBCPP_PUSH_MACROS
 
 _LIBCPP_BEGIN_NAMESPACE_STD
 
-#if _LIBCPP_STD_VER >= 26
+#if _LIBCPP_STD_VER >= 20
 
 template <__libcpp_integer _Tp>
-_LIBCPP_HIDE_FROM_ABI constexpr _Tp add_sat(_Tp __x, _Tp __y) noexcept {
+_LIBCPP_HIDE_FROM_ABI constexpr _Tp __add_sat(_Tp __x, _Tp __y) noexcept {
   if (_Tp __sum; !__builtin_add_overflow(__x, __y, &__sum))
 return __sum;
   // Handle overflow
@@ -46,7 +46,7 @@ _LIBCPP_HIDE_FROM_ABI constexpr _Tp add_sat(_Tp __x, _Tp __y) 
noexcept {
 }
 
 template <__libcpp_integer _Tp>
-_LIBCPP_HIDE_FROM_ABI constexpr _Tp sub_sat(_Tp __x, _Tp __y) noexcept {
+_LIBCPP_HIDE_FROM_ABI constexpr _Tp __sub_sat(_Tp __x, _Tp __y) noexcept {
   if (_Tp __sub; !__builtin_sub_overflow(__x, __y, &__sub))
 return __sub;
   // Handle overflow
@@ -65,7 +65,7 @@ _LIBCPP_HIDE_FROM_ABI constexpr _Tp sub_sat(_Tp __x, _Tp __y) 
noexcept {
 }
 
 template <__libcpp_integer _Tp>
-_LIBCPP_HIDE_FROM_ABI constexpr _Tp mul_sat(_Tp __x, _Tp __y) noexcept {
+_LIBCPP_HIDE_FROM_ABI constexpr _Tp __mul_sat(_Tp __x, _Tp __y) noexcept {
   if (_Tp __mul; !__builtin_mul_overflow(__x, __y, &__mul))
 return __mul;
   // Handle overflow
@@ -81,7 +81,7 @@ _LIBCPP_HIDE_FROM_ABI constexpr _Tp mul_sat(_Tp __x, _Tp __y) 
noexcept {
 }
 
 template <__libcpp_integer _Tp>
-_LIBCPP_HIDE_FROM_ABI constexpr _Tp div_sat(_Tp __x, _Tp __y) noexcept {
+_LIBCPP_HIDE_FROM_ABI constexpr _Tp __div_sat(_Tp __x, _Tp __y) noexcept {
   _LIBCPP_ASSERT_UNCATEGORIZED(__y != 0, "Division by 0 is undefined");
   if constexpr (__libcpp_unsigned_integer<_Tp>) {
 return __x / __y;
@@ -94,7 +94,7 @@ _LIBCPP_HIDE_FROM_ABI constexpr _Tp div_sat(_Tp __x, _Tp __y) 
noexcept {
 }
 
 template <__libcpp_integer _Rp, __libcpp_integer _Tp>
-_LIBCPP_HIDE_FROM_ABI constexpr _Rp saturate_cast(_Tp __x) noexcept {
+_LIBCPP_HIDE_FROM_ABI constexpr _Rp __saturate_cast(_Tp __x) noexcept {
   // Saturation is impossible edge case when ((min _Rp) < (min _Tp) && (max 
_Rp) > (max _Tp)) and it is expected to be
   // optimized out by the compiler.
 
@@ -107,6 +107,35 @@ _LIBCPP_HIDE_FROM_ABI constexpr _Rp saturate_cast(_Tp __x) 
noexcept {
   return static_cast<_Rp>(__x);
 }
 
+#endif // _LIBCPP_STD_VER >= 20
+
+#if _LIBCPP_STD_VER >= 26
+
+template <__libcpp_integer _Tp>
+_LIBCPP_HIDE_FROM_ABI constexpr _Tp add_sat(_Tp __x, _Tp __y) noexcept {
+  return std::add_sat(__x, __y);
+}
+
+template <__libcpp_integer _Tp>
+_LIBCPP_HIDE_FROM_ABI constexpr _Tp sub_sat(_Tp __x, _Tp __y) noexcept {
+  return std::sub_sat(__x, __y);
+}
+
+template <__libcpp_integer _Tp>
+_LIBCPP_HIDE_FROM_ABI constexpr _Tp mul_sat(_Tp __x, _Tp __y) noexcept {
+  return std::mul_sat(__x, __y);
+}
+
+template <__libcpp_integer _Tp>
+_LIBCPP_HIDE_FROM_ABI constexpr _Tp div_sat(_Tp __x, _Tp __y) noexcept {
+  return std::div_sat(__x, __y);
+}
+
+template <__libcpp_integer _Rp, __libcpp_integer _Tp>
+_LIBCPP_HIDE_FROM_ABI constexpr _Rp saturate_cast(_Tp __x) noexcept {
+  return std::saturate_cast<_Rp>(__x);
+}
+
 #endif // _LIBCPP_STD_VER >= 26
 
 _LIBCPP_END_NAMESPACE_STD

___
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++][TZDB] Fixes reverse time lookups. (PR #89498)

2024-04-20 Thread Mark de Wever via llvm-branch-commits

https://github.com/mordante closed 
https://github.com/llvm/llvm-project/pull/89498
___
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++][TZDB] Fixes reverse time lookups. (PR #89498)

2024-04-20 Thread Mark de Wever via llvm-branch-commits

mordante wrote:

This was not properly stacked, abandoned.

https://github.com/llvm/llvm-project/pull/89498
___
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++][TZDB] Fixes reverse time lookups. (PR #89502)

2024-04-20 Thread Mark de Wever via llvm-branch-commits

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

Testing with the get_info() returning a local_info revealed some issues in the 
reverse lookup. This needed an additional quirck. Also the skipping when not in 
the current continuation optimization was wrong. It prevented merging two 
sys_info objects.

>From 26f7f3abb6398a749810230f08c2ef4db5150e6f Mon Sep 17 00:00:00 2001
From: Mark de Wever 
Date: Wed, 17 Apr 2024 21:00:22 +0200
Subject: [PATCH] [libc++][TZDB] Fixes reverse time lookups.

Testing with the get_info() returning a local_info revealed some issues in
the reverse lookup. This needed an additional quirck. Also the skipping
when not in the current continuation optimization was wrong. It prevented
merging two sys_info objects.
---
 libcxx/src/time_zone.cpp  | 19 -
 .../get_info.sys_time.pass.cpp| 76 +++
 2 files changed, 91 insertions(+), 4 deletions(-)

diff --git a/libcxx/src/time_zone.cpp b/libcxx/src/time_zone.cpp
index aef6ac674a11e6..928f3d2855e456 100644
--- a/libcxx/src/time_zone.cpp
+++ b/libcxx/src/time_zone.cpp
@@ -567,11 +567,22 @@ __first_rule(seconds __stdoff, const 
vector<__tz::__rule>& __rules) {
 false};
   }
 
-  __named_rule_until __continuation_end{__continuation};
-  if (__time >= __continuation_end.__until() && 
!__continuation_end.__needs_adjustment())
-// note std::unexpected(__end); is ambiguous with 
std::unexpected() in ,
-return __sys_info_result{std::unexpect, __continuation_end.__until()};
+  if (__rule->__save.__time != 0s) {
+// another fix for America/Punta_Arenas when not at the start of the
+// sys_info object.
+seconds __save = __rule->__save.__time;
+if (__continuation_begin >= __rule_begin - __save && __time < 
__next.first) {
+  return __sys_info{
+  sys_info{__continuation_begin,
+   __next.first,
+   __continuation.__stdoff + __save,
+   chrono::duration_cast(__save),
+   chrono::__format(__continuation, __rule->__letters, 
__save)},
+  false};
+}
+  }
 
+  __named_rule_until __continuation_end{__continuation};
   while (__next.second != __rules.end()) {
 #ifdef PRINT
 std::print(
diff --git 
a/libcxx/test/std/time/time.zone/time.zone.timezone/time.zone.members/get_info.sys_time.pass.cpp
 
b/libcxx/test/std/time/time.zone/time.zone.timezone/time.zone.members/get_info.sys_time.pass.cpp
index 25d2ff11d09341..1a1705d5ae59a5 100644
--- 
a/libcxx/test/std/time/time.zone/time.zone.timezone/time.zone.members/get_info.sys_time.pass.cpp
+++ 
b/libcxx/test/std/time/time.zone/time.zone.timezone/time.zone.members/get_info.sys_time.pass.cpp
@@ -1299,6 +1299,78 @@ static void test_america_indiana_knox() {
tz->get_info(to_sys_seconds(2006y, std::chrono::October, 29d, 
6h, 59min, 59s)));
 }
 
+static void test_america_punta_arenas() {
+  // Z America/Punta_Arenas -4:43:40 - LMT 1890
+  // ...
+  // -4 - -04 1919 Jul
+  // -4:42:45 - SMT 1927 S
+  // -5 x -05/-04 1932 S
+  // ...
+  //
+  // R x 1927 1931 - S 1 0 1 -
+  // R x 1928 1932 - Ap 1 0 0 -
+  // ...
+
+  using namespace std::literals::chrono_literals;
+  const std::chrono::time_zone* tz = 
std::chrono::locate_zone("America/Punta_Arenas");
+
+  assert_equal(
+  std::chrono::sys_info(
+  to_sys_seconds(1927y, std::chrono::September, 1d, 4h, 42min, 45s),
+  to_sys_seconds(1928y, std::chrono::April, 1d, 4h),
+  -4h,
+  60min,
+  "-04"),
+  tz->get_info(to_sys_seconds(1927y, std::chrono::September, 1d, 4h, 
42min, 45s)));
+
+  assert_equal(
+  std::chrono::sys_info(
+  to_sys_seconds(1927y, std::chrono::September, 1d, 4h, 42min, 45s),
+  to_sys_seconds(1928y, std::chrono::April, 1d, 4h),
+  -4h,
+  60min,
+  "-04"),
+  tz->get_info(to_sys_seconds(1928y, std::chrono::April, 1d, 3h, 59min, 
59s)));
+}
+
+static void test_europ_ljubljana() {
+  // Z Europe/Ljubljana 0:58:4 - LMT 1884
+  // 1 - CET 1941 Ap 18 23
+  // 1 c CE%sT 1945 May 8 2s
+  // 1 1 CEST 1945 S 16 2s
+  // 1 - CET 1982 N 27
+  // 1 E CE%sT
+  //
+  // ...
+  // R c 1943 o - O 4 2s 0 -
+  // R c 1944 1945 - Ap M>=1 2s 1 S
+  // R c 1944 o - O 2 2s 0 -
+  // R c 1945 o - S 16 2s 0 -
+  // R c 1977 1980 - Ap Su>=1 2s 1 S
+  // ...
+
+  using namespace std::literals::chrono_literals;
+  const std::chrono::time_zone* tz = 
std::chrono::locate_zone("Europe/Ljubljana");
+
+  assert_equal(
+  std::chrono::sys_info(
+  to_sys_seconds(1945y, std::chrono::April, 2d, 1h),
+  to_sys_seconds(1945y, std::chrono::September, 16d, 1h),
+  2h,
+  60min,
+  "CEST"),
+  tz->get_info(to_sys_seconds(1945y, std::chrono::April, 2d, 1h)));
+
+  assert_equal(
+  std::chrono::sys_info(
+  to_sys_seconds(1945y, std::chrono::April, 2d, 1h),
+  to_sys_seconds(1945y, std::chrono::September, 

[llvm-branch-commits] [libcxx] [libc++][TZDB] Fixes reverse time lookups. (PR #89498)

2024-04-20 Thread Mark de Wever via llvm-branch-commits

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

Testing with the get_info() returning a local_info revealed some issues in the 
reverse lookup. This needed an additional quirck. Also the skipping when not in 
the current continuation optimization was wrong. It prevented merging two 
sys_info objects.

>From 26f7f3abb6398a749810230f08c2ef4db5150e6f Mon Sep 17 00:00:00 2001
From: Mark de Wever 
Date: Wed, 17 Apr 2024 21:00:22 +0200
Subject: [PATCH] [libc++][TZDB] Fixes reverse time lookups.

Testing with the get_info() returning a local_info revealed some issues in
the reverse lookup. This needed an additional quirck. Also the skipping
when not in the current continuation optimization was wrong. It prevented
merging two sys_info objects.
---
 libcxx/src/time_zone.cpp  | 19 -
 .../get_info.sys_time.pass.cpp| 76 +++
 2 files changed, 91 insertions(+), 4 deletions(-)

diff --git a/libcxx/src/time_zone.cpp b/libcxx/src/time_zone.cpp
index aef6ac674a11e6..928f3d2855e456 100644
--- a/libcxx/src/time_zone.cpp
+++ b/libcxx/src/time_zone.cpp
@@ -567,11 +567,22 @@ __first_rule(seconds __stdoff, const 
vector<__tz::__rule>& __rules) {
 false};
   }
 
-  __named_rule_until __continuation_end{__continuation};
-  if (__time >= __continuation_end.__until() && 
!__continuation_end.__needs_adjustment())
-// note std::unexpected(__end); is ambiguous with 
std::unexpected() in ,
-return __sys_info_result{std::unexpect, __continuation_end.__until()};
+  if (__rule->__save.__time != 0s) {
+// another fix for America/Punta_Arenas when not at the start of the
+// sys_info object.
+seconds __save = __rule->__save.__time;
+if (__continuation_begin >= __rule_begin - __save && __time < 
__next.first) {
+  return __sys_info{
+  sys_info{__continuation_begin,
+   __next.first,
+   __continuation.__stdoff + __save,
+   chrono::duration_cast(__save),
+   chrono::__format(__continuation, __rule->__letters, 
__save)},
+  false};
+}
+  }
 
+  __named_rule_until __continuation_end{__continuation};
   while (__next.second != __rules.end()) {
 #ifdef PRINT
 std::print(
diff --git 
a/libcxx/test/std/time/time.zone/time.zone.timezone/time.zone.members/get_info.sys_time.pass.cpp
 
b/libcxx/test/std/time/time.zone/time.zone.timezone/time.zone.members/get_info.sys_time.pass.cpp
index 25d2ff11d09341..1a1705d5ae59a5 100644
--- 
a/libcxx/test/std/time/time.zone/time.zone.timezone/time.zone.members/get_info.sys_time.pass.cpp
+++ 
b/libcxx/test/std/time/time.zone/time.zone.timezone/time.zone.members/get_info.sys_time.pass.cpp
@@ -1299,6 +1299,78 @@ static void test_america_indiana_knox() {
tz->get_info(to_sys_seconds(2006y, std::chrono::October, 29d, 
6h, 59min, 59s)));
 }
 
+static void test_america_punta_arenas() {
+  // Z America/Punta_Arenas -4:43:40 - LMT 1890
+  // ...
+  // -4 - -04 1919 Jul
+  // -4:42:45 - SMT 1927 S
+  // -5 x -05/-04 1932 S
+  // ...
+  //
+  // R x 1927 1931 - S 1 0 1 -
+  // R x 1928 1932 - Ap 1 0 0 -
+  // ...
+
+  using namespace std::literals::chrono_literals;
+  const std::chrono::time_zone* tz = 
std::chrono::locate_zone("America/Punta_Arenas");
+
+  assert_equal(
+  std::chrono::sys_info(
+  to_sys_seconds(1927y, std::chrono::September, 1d, 4h, 42min, 45s),
+  to_sys_seconds(1928y, std::chrono::April, 1d, 4h),
+  -4h,
+  60min,
+  "-04"),
+  tz->get_info(to_sys_seconds(1927y, std::chrono::September, 1d, 4h, 
42min, 45s)));
+
+  assert_equal(
+  std::chrono::sys_info(
+  to_sys_seconds(1927y, std::chrono::September, 1d, 4h, 42min, 45s),
+  to_sys_seconds(1928y, std::chrono::April, 1d, 4h),
+  -4h,
+  60min,
+  "-04"),
+  tz->get_info(to_sys_seconds(1928y, std::chrono::April, 1d, 3h, 59min, 
59s)));
+}
+
+static void test_europ_ljubljana() {
+  // Z Europe/Ljubljana 0:58:4 - LMT 1884
+  // 1 - CET 1941 Ap 18 23
+  // 1 c CE%sT 1945 May 8 2s
+  // 1 1 CEST 1945 S 16 2s
+  // 1 - CET 1982 N 27
+  // 1 E CE%sT
+  //
+  // ...
+  // R c 1943 o - O 4 2s 0 -
+  // R c 1944 1945 - Ap M>=1 2s 1 S
+  // R c 1944 o - O 2 2s 0 -
+  // R c 1945 o - S 16 2s 0 -
+  // R c 1977 1980 - Ap Su>=1 2s 1 S
+  // ...
+
+  using namespace std::literals::chrono_literals;
+  const std::chrono::time_zone* tz = 
std::chrono::locate_zone("Europe/Ljubljana");
+
+  assert_equal(
+  std::chrono::sys_info(
+  to_sys_seconds(1945y, std::chrono::April, 2d, 1h),
+  to_sys_seconds(1945y, std::chrono::September, 16d, 1h),
+  2h,
+  60min,
+  "CEST"),
+  tz->get_info(to_sys_seconds(1945y, std::chrono::April, 2d, 1h)));
+
+  assert_equal(
+  std::chrono::sys_info(
+  to_sys_seconds(1945y, std::chrono::April, 2d, 1h),
+  to_sys_seconds(1945y, std::chrono::September, 

[llvm-branch-commits] [libcxx] [libc++][chrono] Fixes format output of negative values. (PR #89408)

2024-04-19 Thread Mark de Wever via llvm-branch-commits

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

The negative values were shown as

  1900-01-01 00:01:39.-0001

after the changes they are shown as

  1900-01-01 00:01:39.9

>From 11fa6e806dd9a2a6f0a036041de8245f5bcd Mon Sep 17 00:00:00 2001
From: Mark de Wever 
Date: Tue, 16 Apr 2024 20:57:19 +0200
Subject: [PATCH] [libc++][chrono] Fixes format output of negative values.

The negative values were shown as

  1900-01-01 00:01:39.-0001

after the changes they are shown as

  1900-01-01 00:01:39.9
---
 libcxx/include/__chrono/formatter.h   |  3 ++
 .../time.clock.file/ostream.pass.cpp  | 54 +++
 .../time.clock.local/ostream.pass.cpp | 54 +++
 .../sys_time.ostream.pass.cpp | 54 +++
 4 files changed, 165 insertions(+)

diff --git a/libcxx/include/__chrono/formatter.h 
b/libcxx/include/__chrono/formatter.h
index 226fccbee6d133..058e9ac97bc941 100644
--- a/libcxx/include/__chrono/formatter.h
+++ b/libcxx/include/__chrono/formatter.h
@@ -88,6 +88,9 @@ __format_sub_seconds(basic_stringstream<_CharT>& __sstr, 
const chrono::duration<
   using __duration = chrono::duration<_Rep, _Period>;
 
   auto __fraction = __value - chrono::duration_cast(__value);
+  // Converts a negative fraction to its positive value.
+  if (__value < chrono::seconds{0})
+__fraction += chrono::seconds{1};
   if constexpr (chrono::treat_as_floating_point_v<_Rep>)
 // When the floating-point value has digits itself they are ignored based
 // on the wording in [tab:time.format.spec]
diff --git a/libcxx/test/std/time/time.clock/time.clock.file/ostream.pass.cpp 
b/libcxx/test/std/time/time.clock/time.clock.file/ostream.pass.cpp
index 18a4506b91566b..99d56002e9c391 100644
--- a/libcxx/test/std/time/time.clock/time.clock.file/ostream.pass.cpp
+++ b/libcxx/test/std/time/time.clock/time.clock.file/ostream.pass.cpp
@@ -71,6 +71,24 @@ template 
 static void test_c() {
   using namespace std::literals::chrono_literals;
 
+  
assert(stream_c_locale(std::chrono::file_time{-946'688'523'123'456'789ns})
 ==
+ SV("1940-01-01 22:57:56.876543211"));
+
+  
assert(stream_c_locale(std::chrono::file_time{-946'688'523'123'456us})
 ==
+ SV("1940-01-01 22:57:56.876544"));
+
+  
assert(stream_c_locale(std::chrono::file_time{-946'688'523'123ms})
 ==
+ SV("1940-01-01 22:57:56.877"));
+
+  
assert(stream_c_locale(std::chrono::file_time{-1ns})
 ==
+ SV("1969-12-31 23:59:59.9"));
+
+  
assert(stream_c_locale(std::chrono::file_time{0ns})
 ==
+ SV("1970-01-01 00:00:00.0"));
+
+  
assert(stream_c_locale(std::chrono::file_time{1ns})
 ==
+ SV("1970-01-01 00:00:00.1"));
+
   
assert(stream_c_locale(file_time{946'688'523'123'456'789ns})
 ==
  SV("2000-01-01 01:02:03.123456789"));
   
assert(stream_c_locale(file_time{946'688'523'123'456us})
 ==
@@ -107,6 +125,24 @@ template 
 static void test_fr_FR() {
   using namespace std::literals::chrono_literals;
 
+  
assert(stream_fr_FR_locale(std::chrono::file_time{-946'688'523'123'456'789ns})
 ==
+ SV("1940-01-01 22:57:56,876543211"));
+
+  
assert(stream_fr_FR_locale(std::chrono::file_time{-946'688'523'123'456us})
 ==
+ SV("1940-01-01 22:57:56,876544"));
+
+  
assert(stream_fr_FR_locale(std::chrono::file_time{-946'688'523'123ms})
 ==
+ SV("1940-01-01 22:57:56,877"));
+
+  
assert(stream_fr_FR_locale(std::chrono::file_time{-1ns})
 ==
+ SV("1969-12-31 23:59:59,9"));
+
+  
assert(stream_fr_FR_locale(std::chrono::file_time{0ns})
 ==
+ SV("1970-01-01 00:00:00,0"));
+
+  
assert(stream_fr_FR_locale(std::chrono::file_time{1ns})
 ==
+ SV("1970-01-01 00:00:00,1"));
+
   
assert(stream_fr_FR_locale(file_time{946'688'523'123'456'789ns})
 ==
  SV("2000-01-01 01:02:03,123456789"));
   
assert(stream_fr_FR_locale(file_time{946'688'523'123'456us})
 ==
@@ -144,6 +180,24 @@ template 
 static void test_ja_JP() {
   using namespace std::literals::chrono_literals;
 
+  
assert(stream_ja_JP_locale(std::chrono::file_time{-946'688'523'123'456'789ns})
 ==
+ SV("1940-01-01 22:57:56.876543211"));
+
+  
assert(stream_ja_JP_locale(std::chrono::file_time{-946'688'523'123'456us})
 ==
+ SV("1940-01-01 22:57:56.876544"));
+
+  
assert(stream_ja_JP_locale(std::chrono::file_time{-946'688'523'123ms})
 ==
+ SV("1940-01-01 22:57:56.877"));
+
+  
assert(stream_ja_JP_locale(std::chrono::file_time{-1ns})
 ==
+ SV("1969-12-31 23:59:59.9"));
+
+  
assert(stream_ja_JP_locale(std::chrono::file_time{0ns})
 ==
+ SV("1970-01-01 00:00:00.0"));
+
+  
assert(stream_ja_JP_locale(std::chrono::file_time{1ns})
 ==
+ SV("1970-01-01 00:00:00.1"));
+
   
assert(stream_ja_JP_locale(file_time{946'688'523'123'456'789ns})
 ==
  SV("2000-01-01 01:02:03.123456789"));
   

[llvm-branch-commits] [libcxx] [libc++][TZDB] Adds local_info formatter. (PR #86256)

2024-04-13 Thread Mark de Wever via llvm-branch-commits

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

>From 73d01a392239c643c1636e9b34310c42f20b3c90 Mon Sep 17 00:00:00 2001
From: Mark de Wever 
Date: Thu, 14 Mar 2024 21:10:58 +0100
Subject: [PATCH] [libc++][TZDB] Adds local_info formatter.

Note the code using a local_info object will be done in a separate
commit.

Implements parts of:
- P0355 Extending to Calendars and Time Zones
- P1361 Integration of chrono with text formatting
---
 libcxx/docs/Status/FormatPaper.csv|   2 +-
 libcxx/include/CMakeLists.txt |   1 +
 libcxx/include/__chrono/convert_to_tm.h   |   3 +
 libcxx/include/__chrono/formatter.h   |  20 +++
 libcxx/include/__chrono/local_info.h  |  50 +++
 libcxx/include/__chrono/ostream.h |  22 +++
 libcxx/include/chrono |  16 +++
 libcxx/include/libcxx.imp |   1 +
 libcxx/include/module.modulemap   |   1 +
 libcxx/modules/std/chrono.inc |   1 +
 .../time.zone.info.local/ostream.pass.cpp | 114 
 .../time.syn/formatter.local_info.pass.cpp| 126 ++
 .../time.zone.info.local/ostream.pass.cpp |  53 
 .../concept.formattable.compile.pass.cpp  |   2 +-
 14 files changed, 410 insertions(+), 2 deletions(-)
 create mode 100644 libcxx/include/__chrono/local_info.h
 create mode 100644 
libcxx/test/libcxx/time/time.zone/time.zone.info/time.zone.info.local/ostream.pass.cpp
 create mode 100644 libcxx/test/std/time/time.syn/formatter.local_info.pass.cpp
 create mode 100644 
libcxx/test/std/time/time.zone/time.zone.info/time.zone.info.local/ostream.pass.cpp

diff --git a/libcxx/docs/Status/FormatPaper.csv 
b/libcxx/docs/Status/FormatPaper.csv
index 8ace18815f5375..f29f1f7ca74875 100644
--- a/libcxx/docs/Status/FormatPaper.csv
+++ b/libcxx/docs/Status/FormatPaper.csv
@@ -25,7 +25,7 @@ Section,Description,Dependencies,Assignee,Status,First 
released version
 `[time.syn] `_,"Formatter 
``chrono::year_month_weekday_last``",,Mark de Wever,|Complete|,16.0
 `[time.syn] `_,"Formatter 
``chrono::hh_mm_ss>``",,Mark de Wever,|Complete|,17.0
 `[time.syn] `_,"Formatter 
``chrono::sys_info``",,Mark de Wever,|Complete|,19.0
-`[time.syn] `_,"Formatter 
``chrono::local_info``",A  implementation,Mark de Wever,,
+`[time.syn] `_,"Formatter 
``chrono::local_info``",,Mark de Wever,|Complete|,19.0
 `[time.syn] `_,"Formatter 
``chrono::zoned_time``",A  
implementation,Mark de Wever,,
 
 "`P2693R1 `__","Formatting ``thread::id`` and 
``stacktrace``"
diff --git a/libcxx/include/CMakeLists.txt b/libcxx/include/CMakeLists.txt
index a4a58a787ee9ae..ac46b545ea75d2 100644
--- a/libcxx/include/CMakeLists.txt
+++ b/libcxx/include/CMakeLists.txt
@@ -284,6 +284,7 @@ set(files
   __chrono/high_resolution_clock.h
   __chrono/leap_second.h
   __chrono/literals.h
+  __chrono/local_info.h
   __chrono/month.h
   __chrono/month_weekday.h
   __chrono/monthday.h
diff --git a/libcxx/include/__chrono/convert_to_tm.h 
b/libcxx/include/__chrono/convert_to_tm.h
index d2c5cf922ba671..f7256db3bea661 100644
--- a/libcxx/include/__chrono/convert_to_tm.h
+++ b/libcxx/include/__chrono/convert_to_tm.h
@@ -16,6 +16,7 @@
 #include <__chrono/duration.h>
 #include <__chrono/file_clock.h>
 #include <__chrono/hh_mm_ss.h>
+#include <__chrono/local_info.h>
 #include <__chrono/month.h>
 #include <__chrono/month_weekday.h>
 #include <__chrono/monthday.h>
@@ -175,6 +176,8 @@ _LIBCPP_HIDE_FROM_ABI _Tm __convert_to_tm(const _ChronoT& 
__value) {
 #  if !defined(_LIBCPP_HAS_NO_INCOMPLETE_TZDB)
   } else if constexpr (same_as<_ChronoT, chrono::sys_info>) {
 // Has no time information.
+  } else if constexpr (same_as<_ChronoT, chrono::local_info>) {
+// Has no time information.
 #  endif
   } else
 static_assert(sizeof(_ChronoT) == 0, "Add the missing type 
specialization");
diff --git a/libcxx/include/__chrono/formatter.h 
b/libcxx/include/__chrono/formatter.h
index 79192fa103fbdb..a090eb0bfcc88a 100644
--- a/libcxx/include/__chrono/formatter.h
+++ b/libcxx/include/__chrono/formatter.h
@@ -18,6 +18,7 @@
 #include <__chrono/duration.h>
 #include <__chrono/file_clock.h>
 #include <__chrono/hh_mm_ss.h>
+#include <__chrono/local_info.h>
 #include <__chrono/month.h>
 #include <__chrono/month_weekday.h>
 #include <__chrono/monthday.h>
@@ -420,6 +421,8 @@ _LIBCPP_HIDE_FROM_ABI constexpr bool __weekday_ok(const 
_Tp& __value) {
 #  if !defined(_LIBCPP_HAS_NO_INCOMPLETE_TZDB)
   else if constexpr (same_as<_Tp, chrono::sys_info>)
 return true;
+  else if constexpr (same_as<_Tp, chrono::local_info>)
+return true;
 #  endif
   else
 static_assert(sizeof(_Tp) == 0, "Add the missing type specialization");
@@ -464,6 +467,8 @@ _LIBCPP_HIDE_FROM_ABI 

[llvm-branch-commits] [libcxx] [libc++][TZDB] Adds local_info formatter. (PR #86256)

2024-04-13 Thread Mark de Wever via llvm-branch-commits

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

>From 42728d0c66c0a9592949d7bad611bd7d8fe1cd5e Mon Sep 17 00:00:00 2001
From: Mark de Wever 
Date: Thu, 14 Mar 2024 21:10:58 +0100
Subject: [PATCH] [libc++][TZDB] Adds local_info formatter.

Note the code using a local_info object will be done in a separate
commit.

Implements parts of:
- P0355 Extending to Calendars and Time Zones
- P1361 Integration of chrono with text formatting
---
 libcxx/docs/Status/FormatPaper.csv|   2 +-
 libcxx/include/CMakeLists.txt |   1 +
 libcxx/include/__chrono/convert_to_tm.h   |   3 +
 libcxx/include/__chrono/formatter.h   |  20 +++
 libcxx/include/__chrono/local_info.h  |  50 +++
 libcxx/include/__chrono/ostream.h |  22 +++
 libcxx/include/chrono |  16 +++
 libcxx/include/libcxx.imp |   1 +
 libcxx/include/module.modulemap   |   1 +
 libcxx/modules/std/chrono.inc |   1 +
 .../time.zone.info.local/ostream.pass.cpp | 114 
 .../time.syn/formatter.local_info.pass.cpp| 126 ++
 .../time.zone.info.local/ostream.pass.cpp |  53 
 .../concept.formattable.compile.pass.cpp  |   2 +-
 14 files changed, 410 insertions(+), 2 deletions(-)
 create mode 100644 libcxx/include/__chrono/local_info.h
 create mode 100644 
libcxx/test/libcxx/time/time.zone/time.zone.info/time.zone.info.local/ostream.pass.cpp
 create mode 100644 libcxx/test/std/time/time.syn/formatter.local_info.pass.cpp
 create mode 100644 
libcxx/test/std/time/time.zone/time.zone.info/time.zone.info.local/ostream.pass.cpp

diff --git a/libcxx/docs/Status/FormatPaper.csv 
b/libcxx/docs/Status/FormatPaper.csv
index 8ace18815f5375..f29f1f7ca74875 100644
--- a/libcxx/docs/Status/FormatPaper.csv
+++ b/libcxx/docs/Status/FormatPaper.csv
@@ -25,7 +25,7 @@ Section,Description,Dependencies,Assignee,Status,First 
released version
 `[time.syn] `_,"Formatter 
``chrono::year_month_weekday_last``",,Mark de Wever,|Complete|,16.0
 `[time.syn] `_,"Formatter 
``chrono::hh_mm_ss>``",,Mark de Wever,|Complete|,17.0
 `[time.syn] `_,"Formatter 
``chrono::sys_info``",,Mark de Wever,|Complete|,19.0
-`[time.syn] `_,"Formatter 
``chrono::local_info``",A  implementation,Mark de Wever,,
+`[time.syn] `_,"Formatter 
``chrono::local_info``",,Mark de Wever,|Complete|,19.0
 `[time.syn] `_,"Formatter 
``chrono::zoned_time``",A  
implementation,Mark de Wever,,
 
 "`P2693R1 `__","Formatting ``thread::id`` and 
``stacktrace``"
diff --git a/libcxx/include/CMakeLists.txt b/libcxx/include/CMakeLists.txt
index a4a58a787ee9ae..ac46b545ea75d2 100644
--- a/libcxx/include/CMakeLists.txt
+++ b/libcxx/include/CMakeLists.txt
@@ -284,6 +284,7 @@ set(files
   __chrono/high_resolution_clock.h
   __chrono/leap_second.h
   __chrono/literals.h
+  __chrono/local_info.h
   __chrono/month.h
   __chrono/month_weekday.h
   __chrono/monthday.h
diff --git a/libcxx/include/__chrono/convert_to_tm.h 
b/libcxx/include/__chrono/convert_to_tm.h
index d2c5cf922ba671..f7256db3bea661 100644
--- a/libcxx/include/__chrono/convert_to_tm.h
+++ b/libcxx/include/__chrono/convert_to_tm.h
@@ -16,6 +16,7 @@
 #include <__chrono/duration.h>
 #include <__chrono/file_clock.h>
 #include <__chrono/hh_mm_ss.h>
+#include <__chrono/local_info.h>
 #include <__chrono/month.h>
 #include <__chrono/month_weekday.h>
 #include <__chrono/monthday.h>
@@ -175,6 +176,8 @@ _LIBCPP_HIDE_FROM_ABI _Tm __convert_to_tm(const _ChronoT& 
__value) {
 #  if !defined(_LIBCPP_HAS_NO_INCOMPLETE_TZDB)
   } else if constexpr (same_as<_ChronoT, chrono::sys_info>) {
 // Has no time information.
+  } else if constexpr (same_as<_ChronoT, chrono::local_info>) {
+// Has no time information.
 #  endif
   } else
 static_assert(sizeof(_ChronoT) == 0, "Add the missing type 
specialization");
diff --git a/libcxx/include/__chrono/formatter.h 
b/libcxx/include/__chrono/formatter.h
index 79192fa103fbdb..a090eb0bfcc88a 100644
--- a/libcxx/include/__chrono/formatter.h
+++ b/libcxx/include/__chrono/formatter.h
@@ -18,6 +18,7 @@
 #include <__chrono/duration.h>
 #include <__chrono/file_clock.h>
 #include <__chrono/hh_mm_ss.h>
+#include <__chrono/local_info.h>
 #include <__chrono/month.h>
 #include <__chrono/month_weekday.h>
 #include <__chrono/monthday.h>
@@ -420,6 +421,8 @@ _LIBCPP_HIDE_FROM_ABI constexpr bool __weekday_ok(const 
_Tp& __value) {
 #  if !defined(_LIBCPP_HAS_NO_INCOMPLETE_TZDB)
   else if constexpr (same_as<_Tp, chrono::sys_info>)
 return true;
+  else if constexpr (same_as<_Tp, chrono::local_info>)
+return true;
 #  endif
   else
 static_assert(sizeof(_Tp) == 0, "Add the missing type specialization");
@@ -464,6 +467,8 @@ _LIBCPP_HIDE_FROM_ABI 

[llvm-branch-commits] [libcxx] [libc++][TZDB] Adds sys_info formatter. (PR #85896)

2024-04-13 Thread Mark de Wever via llvm-branch-commits

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

>From 96bc907e4f38cd771bc8fed3936932b841c6bd26 Mon Sep 17 00:00:00 2001
From: Mark de Wever 
Date: Sun, 10 Mar 2024 17:49:39 +0100
Subject: [PATCH] [libc++][TZDB] Adds sys_info formatter.

Implements parts of:
- P0355 Extending  to Calendars and Time Zones
- P1361 Integration of chrono with text formatting
---
 libcxx/docs/Status/FormatPaper.csv|   2 +-
 libcxx/include/__chrono/convert_to_tm.h   |   5 +
 libcxx/include/__chrono/formatter.h   |  44 +-
 libcxx/include/__chrono/ostream.h |  20 +++
 libcxx/include/__chrono/sys_info.h|   2 +-
 libcxx/include/chrono |   5 +
 .../time.zone.info.sys/ostream.pass.cpp   |  74 ++
 .../time/time.syn/formatter.sys_info.pass.cpp | 137 ++
 .../time.zone.info.sys/ostream.pass.cpp   |  52 +++
 .../concept.formattable.compile.pass.cpp  |   4 +-
 libcxx/test/support/test_macros.h |   8 +
 11 files changed, 347 insertions(+), 6 deletions(-)
 create mode 100644 
libcxx/test/libcxx/time/time.zone/time.zone.info/time.zone.info.sys/ostream.pass.cpp
 create mode 100644 libcxx/test/std/time/time.syn/formatter.sys_info.pass.cpp
 create mode 100644 
libcxx/test/std/time/time.zone/time.zone.info/time.zone.info.sys/ostream.pass.cpp

diff --git a/libcxx/docs/Status/FormatPaper.csv 
b/libcxx/docs/Status/FormatPaper.csv
index e9d407e79e2539..8ace18815f5375 100644
--- a/libcxx/docs/Status/FormatPaper.csv
+++ b/libcxx/docs/Status/FormatPaper.csv
@@ -24,7 +24,7 @@ Section,Description,Dependencies,Assignee,Status,First 
released version
 `[time.syn] `_,"Formatter 
``chrono::year_month_weekday``",,Mark de Wever,|Complete|,16.0
 `[time.syn] `_,"Formatter 
``chrono::year_month_weekday_last``",,Mark de Wever,|Complete|,16.0
 `[time.syn] `_,"Formatter 
``chrono::hh_mm_ss>``",,Mark de Wever,|Complete|,17.0
-`[time.syn] `_,"Formatter ``chrono::sys_info``",A 
 implementation,Mark de Wever,,
+`[time.syn] `_,"Formatter 
``chrono::sys_info``",,Mark de Wever,|Complete|,19.0
 `[time.syn] `_,"Formatter 
``chrono::local_info``",A  implementation,Mark de Wever,,
 `[time.syn] `_,"Formatter 
``chrono::zoned_time``",A  
implementation,Mark de Wever,,
 
diff --git a/libcxx/include/__chrono/convert_to_tm.h 
b/libcxx/include/__chrono/convert_to_tm.h
index 1301cd6f1f1ada..d2c5cf922ba671 100644
--- a/libcxx/include/__chrono/convert_to_tm.h
+++ b/libcxx/include/__chrono/convert_to_tm.h
@@ -20,6 +20,7 @@
 #include <__chrono/month_weekday.h>
 #include <__chrono/monthday.h>
 #include <__chrono/statically_widen.h>
+#include <__chrono/sys_info.h>
 #include <__chrono/system_clock.h>
 #include <__chrono/time_point.h>
 #include <__chrono/weekday.h>
@@ -171,6 +172,10 @@ _LIBCPP_HIDE_FROM_ABI _Tm __convert_to_tm(const _ChronoT& 
__value) {
   if (__value.hours().count() > 
std::numeric_limits::max())
 std::__throw_format_error("Formatting hh_mm_ss, encountered an hour 
overflow");
 __result.tm_hour = __value.hours().count();
+#  if !defined(_LIBCPP_HAS_NO_INCOMPLETE_TZDB)
+  } else if constexpr (same_as<_ChronoT, chrono::sys_info>) {
+// Has no time information.
+#  endif
   } else
 static_assert(sizeof(_ChronoT) == 0, "Add the missing type 
specialization");
 
diff --git a/libcxx/include/__chrono/formatter.h 
b/libcxx/include/__chrono/formatter.h
index 217979e88c93db..79192fa103fbdb 100644
--- a/libcxx/include/__chrono/formatter.h
+++ b/libcxx/include/__chrono/formatter.h
@@ -24,6 +24,7 @@
 #include <__chrono/ostream.h>
 #include <__chrono/parser_std_format_spec.h>
 #include <__chrono/statically_widen.h>
+#include <__chrono/sys_info.h>
 #include <__chrono/system_clock.h>
 #include <__chrono/time_point.h>
 #include <__chrono/weekday.h>
@@ -185,10 +186,11 @@ __format_zone_offset(basic_stringstream<_CharT>& __sstr, 
chrono::seconds __offse
 
   chrono::hh_mm_ss __hms{__offset};
   std::ostreambuf_iterator<_CharT> __out_it{__sstr};
+  // Note HMS does not allow formatting hours > 23, but the offset is not 
limited to 24H.
+  std::format_to(__out_it, _LIBCPP_STATICALLY_WIDEN(_CharT, "{:02}"), 
__hms.hours().count());
   if (__modifier)
-std::format_to(__out_it, _LIBCPP_STATICALLY_WIDEN(_CharT, "{:%H:%M}"), 
__hms);
-  else
-std::format_to(__out_it, _LIBCPP_STATICALLY_WIDEN(_CharT, "{:%H%M}"), 
__hms);
+__sstr << _CharT(':');
+  std::format_to(__out_it, _LIBCPP_STATICALLY_WIDEN(_CharT, "{:02}"), 
__hms.minutes().count());
 }
 
 // Helper to store the time zone information needed for formatting.
@@ -202,6 +204,12 @@ struct _LIBCPP_HIDE_FROM_ABI __time_zone {
 template 
 _LIBCPP_HIDE_FROM_ABI __time_zone __convert_to_time_zone([[maybe_unused]] 
const _Tp& __value) {
   __time_zone 

[llvm-branch-commits] [libcxx] [libc++][TZDB] Adds sys_info formatter. (PR #85896)

2024-04-12 Thread Mark de Wever via llvm-branch-commits

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

>From e6ae1f07641b79b63b772b866176ffef94a25d48 Mon Sep 17 00:00:00 2001
From: Mark de Wever 
Date: Sun, 10 Mar 2024 17:49:39 +0100
Subject: [PATCH] [libc++][TZDB] Adds sys_info formatter.

Implements parts of:
- P0355 Extending  to Calendars and Time Zones
- P1361 Integration of chrono with text formatting
---
 libcxx/docs/Status/FormatPaper.csv|   2 +-
 libcxx/include/__chrono/convert_to_tm.h   |   5 +
 libcxx/include/__chrono/formatter.h   |  46 +-
 libcxx/include/__chrono/ostream.h |  20 +++
 libcxx/include/__chrono/sys_info.h|   2 +-
 libcxx/include/chrono |   5 +
 .../time.zone.info.sys/ostream.pass.cpp   |  74 ++
 .../time/time.syn/formatter.sys_info.pass.cpp | 137 ++
 .../time.zone.info.sys/ostream.pass.cpp   |  52 +++
 .../concept.formattable.compile.pass.cpp  |   5 +-
 libcxx/test/support/test_macros.h |   8 +
 11 files changed, 350 insertions(+), 6 deletions(-)
 create mode 100644 
libcxx/test/libcxx/time/time.zone/time.zone.info/time.zone.info.sys/ostream.pass.cpp
 create mode 100644 libcxx/test/std/time/time.syn/formatter.sys_info.pass.cpp
 create mode 100644 
libcxx/test/std/time/time.zone/time.zone.info/time.zone.info.sys/ostream.pass.cpp

diff --git a/libcxx/docs/Status/FormatPaper.csv 
b/libcxx/docs/Status/FormatPaper.csv
index e9d407e79e2539..8ace18815f5375 100644
--- a/libcxx/docs/Status/FormatPaper.csv
+++ b/libcxx/docs/Status/FormatPaper.csv
@@ -24,7 +24,7 @@ Section,Description,Dependencies,Assignee,Status,First 
released version
 `[time.syn] `_,"Formatter 
``chrono::year_month_weekday``",,Mark de Wever,|Complete|,16.0
 `[time.syn] `_,"Formatter 
``chrono::year_month_weekday_last``",,Mark de Wever,|Complete|,16.0
 `[time.syn] `_,"Formatter 
``chrono::hh_mm_ss>``",,Mark de Wever,|Complete|,17.0
-`[time.syn] `_,"Formatter ``chrono::sys_info``",A 
 implementation,Mark de Wever,,
+`[time.syn] `_,"Formatter 
``chrono::sys_info``",,Mark de Wever,|Complete|,19.0
 `[time.syn] `_,"Formatter 
``chrono::local_info``",A  implementation,Mark de Wever,,
 `[time.syn] `_,"Formatter 
``chrono::zoned_time``",A  
implementation,Mark de Wever,,
 
diff --git a/libcxx/include/__chrono/convert_to_tm.h 
b/libcxx/include/__chrono/convert_to_tm.h
index 1301cd6f1f1ada..d2c5cf922ba671 100644
--- a/libcxx/include/__chrono/convert_to_tm.h
+++ b/libcxx/include/__chrono/convert_to_tm.h
@@ -20,6 +20,7 @@
 #include <__chrono/month_weekday.h>
 #include <__chrono/monthday.h>
 #include <__chrono/statically_widen.h>
+#include <__chrono/sys_info.h>
 #include <__chrono/system_clock.h>
 #include <__chrono/time_point.h>
 #include <__chrono/weekday.h>
@@ -171,6 +172,10 @@ _LIBCPP_HIDE_FROM_ABI _Tm __convert_to_tm(const _ChronoT& 
__value) {
   if (__value.hours().count() > 
std::numeric_limits::max())
 std::__throw_format_error("Formatting hh_mm_ss, encountered an hour 
overflow");
 __result.tm_hour = __value.hours().count();
+#  if !defined(_LIBCPP_HAS_NO_INCOMPLETE_TZDB)
+  } else if constexpr (same_as<_ChronoT, chrono::sys_info>) {
+// Has no time information.
+#  endif
   } else
 static_assert(sizeof(_ChronoT) == 0, "Add the missing type 
specialization");
 
diff --git a/libcxx/include/__chrono/formatter.h 
b/libcxx/include/__chrono/formatter.h
index 217979e88c93db..e3235a9b5b5cf5 100644
--- a/libcxx/include/__chrono/formatter.h
+++ b/libcxx/include/__chrono/formatter.h
@@ -24,6 +24,7 @@
 #include <__chrono/ostream.h>
 #include <__chrono/parser_std_format_spec.h>
 #include <__chrono/statically_widen.h>
+#include <__chrono/sys_info.h>
 #include <__chrono/system_clock.h>
 #include <__chrono/time_point.h>
 #include <__chrono/weekday.h>
@@ -185,10 +186,11 @@ __format_zone_offset(basic_stringstream<_CharT>& __sstr, 
chrono::seconds __offse
 
   chrono::hh_mm_ss __hms{__offset};
   std::ostreambuf_iterator<_CharT> __out_it{__sstr};
+  // Note HMS does not allow formatting hours > 23, but the offset is not 
limited to 24H.
+  std::format_to(__out_it, _LIBCPP_STATICALLY_WIDEN(_CharT, "{:02}"), 
__hms.hours().count());
   if (__modifier)
-std::format_to(__out_it, _LIBCPP_STATICALLY_WIDEN(_CharT, "{:%H:%M}"), 
__hms);
-  else
-std::format_to(__out_it, _LIBCPP_STATICALLY_WIDEN(_CharT, "{:%H%M}"), 
__hms);
+__sstr << _CharT(':');
+  std::format_to(__out_it, _LIBCPP_STATICALLY_WIDEN(_CharT, "{:02}"), 
__hms.minutes().count());
 }
 
 // Helper to store the time zone information needed for formatting.
@@ -202,6 +204,12 @@ struct _LIBCPP_HIDE_FROM_ABI __time_zone {
 template 
 _LIBCPP_HIDE_FROM_ABI __time_zone __convert_to_time_zone([[maybe_unused]] 
const _Tp& __value) {
   __time_zone 

[llvm-branch-commits] [libcxx] release/18.x: [libcxx] coerce formatter precision to int (#87738) (PR #87801)

2024-04-12 Thread Mark de Wever via llvm-branch-commits

mordante wrote:

> > Is it OK to merge this with the failing test?
> 
> is it possible this was a fix for an XFAIL @mordante ?

This failure is in completely unrelated code. So I'm happy to merge it with the 
CI failure.

https://github.com/llvm/llvm-project/pull/87801
___
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] release/18.x: [libc++] Fix -Wgnu-include-next in stddef.h (#88214) (PR #88419)

2024-04-12 Thread Mark de Wever via llvm-branch-commits

https://github.com/mordante approved this pull request.


https://github.com/llvm/llvm-project/pull/88419
___
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++][TZDB] Adds sys_info formatter. (PR #85896)

2024-04-11 Thread Mark de Wever via llvm-branch-commits

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

>From de4ba883c354ab8510fb0e5e4ad2a09d93000c30 Mon Sep 17 00:00:00 2001
From: Mark de Wever 
Date: Sun, 10 Mar 2024 17:49:39 +0100
Subject: [PATCH] [libc++][TZDB] Adds sys_info formatter.

Implements parts of:
- P0355 Extending  to Calendars and Time Zones
- P1361 Integration of chrono with text formatting
---
 libcxx/docs/Status/FormatPaper.csv|   2 +-
 libcxx/include/__chrono/convert_to_tm.h   |   5 +
 libcxx/include/__chrono/formatter.h   |  44 +-
 libcxx/include/__chrono/ostream.h |  20 +++
 libcxx/include/__chrono/sys_info.h|   2 +-
 libcxx/include/chrono |   5 +
 .../time.zone.info.sys/ostream.pass.cpp   |  74 ++
 .../time/time.syn/formatter.sys_info.pass.cpp | 137 ++
 .../time.zone.info.sys/ostream.pass.cpp   |  52 +++
 .../concept.formattable.compile.pass.cpp  |   2 +-
 10 files changed, 337 insertions(+), 6 deletions(-)
 create mode 100644 
libcxx/test/libcxx/time/time.zone/time.zone.info/time.zone.info.sys/ostream.pass.cpp
 create mode 100644 libcxx/test/std/time/time.syn/formatter.sys_info.pass.cpp
 create mode 100644 
libcxx/test/std/time/time.zone/time.zone.info/time.zone.info.sys/ostream.pass.cpp

diff --git a/libcxx/docs/Status/FormatPaper.csv 
b/libcxx/docs/Status/FormatPaper.csv
index e9d407e79e2539..8ace18815f5375 100644
--- a/libcxx/docs/Status/FormatPaper.csv
+++ b/libcxx/docs/Status/FormatPaper.csv
@@ -24,7 +24,7 @@ Section,Description,Dependencies,Assignee,Status,First 
released version
 `[time.syn] `_,"Formatter 
``chrono::year_month_weekday``",,Mark de Wever,|Complete|,16.0
 `[time.syn] `_,"Formatter 
``chrono::year_month_weekday_last``",,Mark de Wever,|Complete|,16.0
 `[time.syn] `_,"Formatter 
``chrono::hh_mm_ss>``",,Mark de Wever,|Complete|,17.0
-`[time.syn] `_,"Formatter ``chrono::sys_info``",A 
 implementation,Mark de Wever,,
+`[time.syn] `_,"Formatter 
``chrono::sys_info``",,Mark de Wever,|Complete|,19.0
 `[time.syn] `_,"Formatter 
``chrono::local_info``",A  implementation,Mark de Wever,,
 `[time.syn] `_,"Formatter 
``chrono::zoned_time``",A  
implementation,Mark de Wever,,
 
diff --git a/libcxx/include/__chrono/convert_to_tm.h 
b/libcxx/include/__chrono/convert_to_tm.h
index 1301cd6f1f1ada..d2c5cf922ba671 100644
--- a/libcxx/include/__chrono/convert_to_tm.h
+++ b/libcxx/include/__chrono/convert_to_tm.h
@@ -20,6 +20,7 @@
 #include <__chrono/month_weekday.h>
 #include <__chrono/monthday.h>
 #include <__chrono/statically_widen.h>
+#include <__chrono/sys_info.h>
 #include <__chrono/system_clock.h>
 #include <__chrono/time_point.h>
 #include <__chrono/weekday.h>
@@ -171,6 +172,10 @@ _LIBCPP_HIDE_FROM_ABI _Tm __convert_to_tm(const _ChronoT& 
__value) {
   if (__value.hours().count() > 
std::numeric_limits::max())
 std::__throw_format_error("Formatting hh_mm_ss, encountered an hour 
overflow");
 __result.tm_hour = __value.hours().count();
+#  if !defined(_LIBCPP_HAS_NO_INCOMPLETE_TZDB)
+  } else if constexpr (same_as<_ChronoT, chrono::sys_info>) {
+// Has no time information.
+#  endif
   } else
 static_assert(sizeof(_ChronoT) == 0, "Add the missing type 
specialization");
 
diff --git a/libcxx/include/__chrono/formatter.h 
b/libcxx/include/__chrono/formatter.h
index 217979e88c93db..79192fa103fbdb 100644
--- a/libcxx/include/__chrono/formatter.h
+++ b/libcxx/include/__chrono/formatter.h
@@ -24,6 +24,7 @@
 #include <__chrono/ostream.h>
 #include <__chrono/parser_std_format_spec.h>
 #include <__chrono/statically_widen.h>
+#include <__chrono/sys_info.h>
 #include <__chrono/system_clock.h>
 #include <__chrono/time_point.h>
 #include <__chrono/weekday.h>
@@ -185,10 +186,11 @@ __format_zone_offset(basic_stringstream<_CharT>& __sstr, 
chrono::seconds __offse
 
   chrono::hh_mm_ss __hms{__offset};
   std::ostreambuf_iterator<_CharT> __out_it{__sstr};
+  // Note HMS does not allow formatting hours > 23, but the offset is not 
limited to 24H.
+  std::format_to(__out_it, _LIBCPP_STATICALLY_WIDEN(_CharT, "{:02}"), 
__hms.hours().count());
   if (__modifier)
-std::format_to(__out_it, _LIBCPP_STATICALLY_WIDEN(_CharT, "{:%H:%M}"), 
__hms);
-  else
-std::format_to(__out_it, _LIBCPP_STATICALLY_WIDEN(_CharT, "{:%H%M}"), 
__hms);
+__sstr << _CharT(':');
+  std::format_to(__out_it, _LIBCPP_STATICALLY_WIDEN(_CharT, "{:02}"), 
__hms.minutes().count());
 }
 
 // Helper to store the time zone information needed for formatting.
@@ -202,6 +204,12 @@ struct _LIBCPP_HIDE_FROM_ABI __time_zone {
 template 
 _LIBCPP_HIDE_FROM_ABI __time_zone __convert_to_time_zone([[maybe_unused]] 
const _Tp& __value) {
   __time_zone __result;
+#  if 

[llvm-branch-commits] [libcxx] [libc++][chrono] Improves date formatting. (PR #86127)

2024-04-10 Thread Mark de Wever via llvm-branch-commits

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

>From 677956d0923c499f8f6d1f13035f5f60d48ea7c8 Mon Sep 17 00:00:00 2001
From: Mark de Wever 
Date: Thu, 21 Mar 2024 15:22:13 +0100
Subject: [PATCH] [libc++][chrono] Improves date formatting.

The formatting of years has been done manually since the results of %Y
outside the "typical" range may produce unexpected values. The same
applies to %F which is identical to %Y-%m-%d. Note of these conversion
specifiers is affected by the locale used. So it's trivial to manually
handle this case.

This removes several platform specific ifdefs from the tests.
---
 libcxx/include/__chrono/formatter.h   | 16 -
 .../time.cal.ymd.nonmembers/ostream.pass.cpp  | 34 ---
 .../sys_date.ostream.pass.cpp | 34 ---
 .../formatter.year_month_day.pass.cpp | 24 -
 4 files changed, 7 insertions(+), 101 deletions(-)

diff --git a/libcxx/include/__chrono/formatter.h 
b/libcxx/include/__chrono/formatter.h
index 8b8592041a1fb9..217979e88c93db 100644
--- a/libcxx/include/__chrono/formatter.h
+++ b/libcxx/include/__chrono/formatter.h
@@ -322,15 +322,13 @@ _LIBCPP_HIDE_FROM_ABI void 
__format_chrono_using_chrono_specs(
 __formatter::__format_year(__sstr, __t.tm_year + 1900);
 break;
 
-  case _CharT('F'): {
-int __year = __t.tm_year + 1900;
-if (__year < 1000) {
-  __formatter::__format_year(__sstr, __year);
-  __sstr << std::format(_LIBCPP_STATICALLY_WIDEN(_CharT, 
"-{:02}-{:02}"), __t.tm_mon + 1, __t.tm_mday);
-} else
-  __facet.put(
-  {__sstr}, __sstr, _CharT(' '), std::addressof(__t), 
std::to_address(__s), std::to_address(__it + 1));
-  } break;
+  case _CharT('F'):
+// Depending on the platform's libc the range of supported years is
+// limited. Intead of of testing all conditions use the internal
+// implementation unconditionally.
+__formatter::__format_year(__sstr, __t.tm_year + 1900);
+__sstr << std::format(_LIBCPP_STATICALLY_WIDEN(_CharT, 
"-{:02}-{:02}"), __t.tm_mon + 1, __t.tm_mday);
+break;
 
   case _CharT('z'):
 __formatter::__format_zone_offset(__sstr, __z.__offset, false);
diff --git 
a/libcxx/test/std/time/time.cal/time.cal.ymd/time.cal.ymd.nonmembers/ostream.pass.cpp
 
b/libcxx/test/std/time/time.cal/time.cal.ymd/time.cal.ymd.nonmembers/ostream.pass.cpp
index ffc737fcad5dd2..20ffb165558e31 100644
--- 
a/libcxx/test/std/time/time.cal/time.cal.ymd/time.cal.ymd.nonmembers/ostream.pass.cpp
+++ 
b/libcxx/test/std/time/time.cal/time.cal.ymd/time.cal.ymd.nonmembers/ostream.pass.cpp
@@ -13,9 +13,6 @@
 // TODO FMT This test should not require std::to_chars(floating-point)
 // XFAIL: availability-fp_to_chars-missing
 
-// TODO FMT Investigate Windows issues.
-// XFAIL: msvc
-
 // REQUIRES: locale.fr_FR.UTF-8
 // REQUIRES: locale.ja_JP.UTF-8
 
@@ -89,20 +86,9 @@ static void test() {
   TEST_EQUAL(stream_c_locale(
  std::chrono::year_month_day{std::chrono::year{2000}, 
std::chrono::month{2}, std::chrono::day{29}}),
  SV("2000-02-29"));
-
-#if defined(_AIX)
-  TEST_EQUAL(stream_c_locale(
- std::chrono::year_month_day{std::chrono::year{32'767}, 
std::chrono::month{12}, std::chrono::day{31}}),
- SV("+32767-12-31"));
-#elif defined(_WIN32) // defined(_AIX)
-  TEST_EQUAL(stream_c_locale(
- std::chrono::year_month_day{std::chrono::year{32'767}, 
std::chrono::month{12}, std::chrono::day{31}}),
- SV(""));
-#else //  defined(_AIX)
   TEST_EQUAL(stream_c_locale(
  std::chrono::year_month_day{std::chrono::year{32'767}, 
std::chrono::month{12}, std::chrono::day{31}}),
  SV("32767-12-31"));
-#endif// defined(_AIX)
 
   TEST_EQUAL(stream_fr_FR_locale(
  std::chrono::year_month_day{std::chrono::year{-32'768}, 
std::chrono::month{1}, std::chrono::day{1}}),
@@ -122,19 +108,9 @@ static void test() {
   TEST_EQUAL(stream_fr_FR_locale(
  std::chrono::year_month_day{std::chrono::year{2000}, 
std::chrono::month{2}, std::chrono::day{29}}),
  SV("2000-02-29"));
-#if defined(_AIX)
-  TEST_EQUAL(stream_fr_FR_locale(
- std::chrono::year_month_day{std::chrono::year{32'767}, 
std::chrono::month{12}, std::chrono::day{31}}),
- SV("+32767-12-31"));
-#elif defined(_WIN32) // defined(_AIX)
-  TEST_EQUAL(stream_fr_FR_locale(
- std::chrono::year_month_day{std::chrono::year{32'767}, 
std::chrono::month{12}, std::chrono::day{31}}),
- SV(""));
-#else // defined(_AIX)
   TEST_EQUAL(stream_fr_FR_locale(
  std::chrono::year_month_day{std::chrono::year{32'767}, 
std::chrono::month{12}, std::chrono::day{31}}),
  SV("32767-12-31"));
-#endif// defined(_AIX)
 
   

[llvm-branch-commits] [libcxx] [libc++][TZDB] Improves time zone format specifiers. (PR #85797)

2024-04-10 Thread Mark de Wever via llvm-branch-commits

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

>From cb87ecc505cf538eaa657a7cc3b1b282e3e7298d Mon Sep 17 00:00:00 2001
From: Mark de Wever 
Date: Sun, 10 Mar 2024 17:49:39 +0100
Subject: [PATCH] [libc++][TZDB] Improves time zone format specifiers.

Per [tab:time.format.spec]
%z  The offset from UTC as specified in ISO 8601-1:2019, subclause
5.3.4.1. For example -0430 refers to 4 hours 30 minutes behind UTC.
If the offset is zero, + is used. The modified commands %Ez and
%Oz insert a : between the hours and minutes: -04:30. If the offset
information is not available, an exception of type format_error is
thrown.

Typically the modified versions Oz or Ez would have wording like

  The modified command %OS produces the locale's alternative
  representation.

In this case the modified version does not depend on the locale.

This change is a preparation for formatting sys_info which has time zone
information. The function time_put<_CharT>::put() does not have proper
time zone support, therefore it's a manual implementation.

Fixes https://github.com/llvm/llvm-project/issues/78184
---
 libcxx/include/__chrono/formatter.h   | 50 ++-
 .../time.syn/formatter.file_time.pass.cpp | 39 ++-
 .../time/time.syn/formatter.sys_time.pass.cpp | 39 ++-
 3 files changed, 56 insertions(+), 72 deletions(-)

diff --git a/libcxx/include/__chrono/formatter.h 
b/libcxx/include/__chrono/formatter.h
index b64cae529a294d..8b8592041a1fb9 100644
--- a/libcxx/include/__chrono/formatter.h
+++ b/libcxx/include/__chrono/formatter.h
@@ -10,6 +10,7 @@
 #ifndef _LIBCPP___CHRONO_FORMATTER_H
 #define _LIBCPP___CHRONO_FORMATTER_H
 
+#include <__algorithm/ranges_copy.h>
 #include <__chrono/calendar.h>
 #include <__chrono/concepts.h>
 #include <__chrono/convert_to_tm.h>
@@ -170,10 +171,45 @@ _LIBCPP_HIDE_FROM_ABI void 
__format_century(basic_stringstream<_CharT>& __sstr,
   __sstr << std::format(_LIBCPP_STATICALLY_WIDEN(_CharT, "{:02}"), __century);
 }
 
+// Implements the %z format specifier according to [tab:time.format.spec], 
where
+// '__modifier' signals %Oz or %Ez were used. (Both modifiers behave the same,
+// so there is no need to distinguish between them.)
+template 
+_LIBCPP_HIDE_FROM_ABI void
+__format_zone_offset(basic_stringstream<_CharT>& __sstr, chrono::seconds 
__offset, bool __modifier) {
+  if (__offset < 0s) {
+__sstr << _CharT('-');
+__offset = -__offset;
+  } else
+__sstr << _CharT('+');
+
+  chrono::hh_mm_ss __hms{__offset};
+  std::ostreambuf_iterator<_CharT> __out_it{__sstr};
+  if (__modifier)
+std::format_to(__out_it, _LIBCPP_STATICALLY_WIDEN(_CharT, "{:%H:%M}"), 
__hms);
+  else
+std::format_to(__out_it, _LIBCPP_STATICALLY_WIDEN(_CharT, "{:%H%M}"), 
__hms);
+}
+
+// Helper to store the time zone information needed for formatting.
+struct _LIBCPP_HIDE_FROM_ABI __time_zone {
+  // Typically these abbreviations as short and fit in the string's internal
+  // buffer.
+  string __abbrev{"UTC"};
+  chrono::seconds __offset{0};
+};
+
+template 
+_LIBCPP_HIDE_FROM_ABI __time_zone __convert_to_time_zone([[maybe_unused]] 
const _Tp& __value) {
+  __time_zone __result;
+  return __result;
+}
+
 template 
 _LIBCPP_HIDE_FROM_ABI void __format_chrono_using_chrono_specs(
 basic_stringstream<_CharT>& __sstr, const _Tp& __value, 
basic_string_view<_CharT> __chrono_specs) {
   tm __t  = std::__convert_to_tm(__value);
+  __time_zone __z = __formatter::__convert_to_time_zone(__value);
   const auto& __facet = std::use_facet>(__sstr.getloc());
   for (auto __it = __chrono_specs.begin(); __it != __chrono_specs.end(); 
++__it) {
 if (*__it == _CharT('%')) {
@@ -296,9 +332,13 @@ _LIBCPP_HIDE_FROM_ABI void 
__format_chrono_using_chrono_specs(
   {__sstr}, __sstr, _CharT(' '), std::addressof(__t), 
std::to_address(__s), std::to_address(__it + 1));
   } break;
 
+  case _CharT('z'):
+__formatter::__format_zone_offset(__sstr, __z.__offset, false);
+break;
+
   case _CharT('Z'):
-// TODO FMT Add proper timezone support.
-__sstr << _LIBCPP_STATICALLY_WIDEN(_CharT, "UTC");
+// __abbrev is always a char so the copy may convert.
+ranges::copy(__z.__abbrev, std::ostreambuf_iterator<_CharT>{__sstr});
 break;
 
   case _CharT('O'):
@@ -314,9 +354,15 @@ _LIBCPP_HIDE_FROM_ABI void 
__format_chrono_using_chrono_specs(
 break;
   }
 }
+
+// Oz produces the same output as Ez below.
 [[fallthrough]];
   case _CharT('E'):
 ++__it;
+if (*__it == 'z') {
+  __formatter::__format_zone_offset(__sstr, __z.__offset, true);
+  break;
+}
 [[fallthrough]];
   default:
 __facet.put(
diff --git a/libcxx/test/std/time/time.syn/formatter.file_time.pass.cpp 
b/libcxx/test/std/time/time.syn/formatter.file_time.pass.cpp
index 

[llvm-branch-commits] [libcxx] [libc++][format] Improves escaping. (PR #88283)

2024-04-10 Thread Mark de Wever via llvm-branch-commits

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

The change increments the size of the lookup table considerably. The table has 
an "upper boundary" check. The removal of the code units with the property 
Grapheme_Extend=Yes removes the range E0100..E01EF. This breaks the trailing 
large continues section in two parts. This will be improved in a followup patch.

Implements:
- P2713R1 Escaping improvements in std::format
- LWG3965 Incorrect example in [format.string.escaped] p3 for formatting of 
combining characters

Before
---
Benchmark Time CPU   Iterations
---
BM_ascii_escaped95696 ns95459 ns 7341
BM_unicode_escaped  89311 ns89088 ns 7835
BM_cyrillic_escaped 58633 ns58494 ns11964
BM_japanese_escaped 44500 ns44382 ns15780
BM_emoji_escaped99156 ns98911 ns 7075
BM_ascii_escaped 92245 ns92017 ns 7592
BM_unicode_escaped   80970 ns80747 ns 8651
BM_cyrillic_escaped  51253 ns51112 ns13729
BM_japanese_escaped  37252 ns37156 ns18758
BM_emoji_escaped 96226 ns95961 ns 7270

After
---
Benchmark Time CPU   Iterations
---
BM_ascii_escaped   110704 ns   110696 ns 6206
BM_unicode_escaped 101371 ns   101374 ns 6862
BM_cyrillic_escaped 63329 ns63327 ns11013
BM_japanese_escaped 41223 ns41225 ns16938
BM_emoji_escaped   111022 ns   111021 ns 6304
BM_ascii_escaped112441 ns   112443 ns 6231
BM_unicode_escaped  102776 ns   102779 ns 6813
BM_cyrillic_escaped  58977 ns58975 ns11868
BM_japanese_escaped  36885 ns36886 ns18975
BM_emoji_escaped115885 ns   115881 ns 6051

>From 1f06034f8d6fc581b0b3d4c3d1f0ed8ef491979a Mon Sep 17 00:00:00 2001
From: Mark de Wever 
Date: Sat, 3 Feb 2024 17:08:59 +0100
Subject: [PATCH] [libc++][format] Improves escaping.

The change increments the size of the lookup table considerably. The table
has an "upper boundary" check. The removal of the code units with the
property Grapheme_Extend=Yes removes the range E0100..E01EF. This breaks
the trailing large continues section in two parts. This will be improved
in a followup patch.

Implements:
- P2713R1 Escaping improvements in std::format
- LWG3965 Incorrect example in [format.string.escaped] p3 for formatting of 
combining characters

Before
---
Benchmark Time CPU   Iterations
---
BM_ascii_escaped95696 ns95459 ns 7341
BM_unicode_escaped  89311 ns89088 ns 7835
BM_cyrillic_escaped 58633 ns58494 ns11964
BM_japanese_escaped 44500 ns44382 ns15780
BM_emoji_escaped99156 ns98911 ns 7075
BM_ascii_escaped 92245 ns92017 ns 7592
BM_unicode_escaped   80970 ns80747 ns 8651
BM_cyrillic_escaped  51253 ns51112 ns13729
BM_japanese_escaped  37252 ns37156 ns18758
BM_emoji_escaped 96226 ns95961 ns 7270

After
---
Benchmark Time CPU   Iterations
---
BM_ascii_escaped   110704 ns   110696 ns 6206
BM_unicode_escaped 101371 ns   101374 ns 6862
BM_cyrillic_escaped 63329 ns63327 ns11013
BM_japanese_escaped 41223 ns41225 ns16938
BM_emoji_escaped   111022 ns   111021 ns 6304
BM_ascii_escaped112441 ns   112443 ns 6231
BM_unicode_escaped  102776 ns   102779 ns 6813
BM_cyrillic_escaped  58977 ns58975 ns11868
BM_japanese_escaped  36885 ns36886 ns18975
BM_emoji_escaped115885 ns   115881 ns 6051
---
 libcxx/docs/ReleaseNotes/19.rst   |2 +
 libcxx/docs/Status/Cxx23Papers.csv|2 +-
 libcxx/docs/Status/Cxx2cIssues.csv|2 +-
 libcxx/docs/Status/FormatIssues.csv   |2 +-
 .../include/__format/escaped_output_table.h   | 1982 +
 

[llvm-branch-commits] [libcxx] release/18.x: [libcxx] coerce formatter precision to int (#87738) (PR #87801)

2024-04-05 Thread Mark de Wever via llvm-branch-commits

https://github.com/mordante approved this pull request.


https://github.com/llvm/llvm-project/pull/87801
___
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] release/18.x: Reapply [libcxx] [modules] Fix relative paths with absolute LIBCXX_INSTALL_MODULES_DIR (#86020) (PR #86197)

2024-03-28 Thread Mark de Wever via llvm-branch-commits

mordante wrote:

> @mordante Is the test failure legitimate?

I've checked and the test failure is unrelated to this patch.

https://github.com/llvm/llvm-project/pull/86197
___
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++][TZDB] Adds local_info formatter. (PR #86256)

2024-03-22 Thread Mark de Wever via llvm-branch-commits

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

>From 601338a04e28e356f0d9b90448ec2550f8870783 Mon Sep 17 00:00:00 2001
From: Mark de Wever 
Date: Thu, 14 Mar 2024 21:10:58 +0100
Subject: [PATCH] [libc++][TZDB] Adds local_info formatter.

Note the code using a local_info object will be done in a separate
commit.

Implements parts of:
- P0355 Extending to Calendars and Time Zones
- P1361 Integration of chrono with text formatting
---
 libcxx/docs/Status/FormatPaper.csv|   2 +-
 libcxx/include/CMakeLists.txt |   1 +
 libcxx/include/__chrono/convert_to_tm.h   |   3 +
 libcxx/include/__chrono/formatter.h   |  20 +++
 libcxx/include/__chrono/local_info.h  |  50 +++
 libcxx/include/__chrono/ostream.h |  22 +++
 libcxx/include/chrono |  16 +++
 libcxx/include/libcxx.imp |   1 +
 libcxx/include/module.modulemap   |   1 +
 libcxx/modules/std/chrono.inc |   1 +
 .../time.zone.info.local/ostream.pass.cpp | 114 
 .../time.syn/formatter.local_info.pass.cpp| 126 ++
 .../time.zone.info.local/ostream.pass.cpp |  53 
 13 files changed, 409 insertions(+), 1 deletion(-)
 create mode 100644 libcxx/include/__chrono/local_info.h
 create mode 100644 
libcxx/test/libcxx/time/time.zone/time.zone.info/time.zone.info.local/ostream.pass.cpp
 create mode 100644 libcxx/test/std/time/time.syn/formatter.local_info.pass.cpp
 create mode 100644 
libcxx/test/std/time/time.zone/time.zone.info/time.zone.info.local/ostream.pass.cpp

diff --git a/libcxx/docs/Status/FormatPaper.csv 
b/libcxx/docs/Status/FormatPaper.csv
index 32166ec72da753..b1a957c7b65dd1 100644
--- a/libcxx/docs/Status/FormatPaper.csv
+++ b/libcxx/docs/Status/FormatPaper.csv
@@ -25,7 +25,7 @@ Section,Description,Dependencies,Assignee,Status,First 
released version
 `[time.syn] `_,"Formatter 
``chrono::year_month_weekday_last``",,Mark de Wever,|Complete|,16.0
 `[time.syn] `_,"Formatter 
``chrono::hh_mm_ss>``",,Mark de Wever,|Complete|,17.0
 `[time.syn] `_,"Formatter 
``chrono::sys_info``",,Mark de Wever,|Complete|,19.0
-`[time.syn] `_,"Formatter 
``chrono::local_info``",A  implementation,Mark de Wever,,
+`[time.syn] `_,"Formatter 
``chrono::local_info``",,Mark de Wever,|Complete|,19.0
 `[time.syn] `_,"Formatter 
``chrono::zoned_time``",A  
implementation,Mark de Wever,,
 
 `P2286R8 `__,"Formatting ranges"
diff --git a/libcxx/include/CMakeLists.txt b/libcxx/include/CMakeLists.txt
index 2fc329d9e71457..a343e4c69c472c 100644
--- a/libcxx/include/CMakeLists.txt
+++ b/libcxx/include/CMakeLists.txt
@@ -283,6 +283,7 @@ set(files
   __chrono/high_resolution_clock.h
   __chrono/leap_second.h
   __chrono/literals.h
+  __chrono/local_info.h
   __chrono/month.h
   __chrono/month_weekday.h
   __chrono/monthday.h
diff --git a/libcxx/include/__chrono/convert_to_tm.h 
b/libcxx/include/__chrono/convert_to_tm.h
index d2c5cf922ba671..f7256db3bea661 100644
--- a/libcxx/include/__chrono/convert_to_tm.h
+++ b/libcxx/include/__chrono/convert_to_tm.h
@@ -16,6 +16,7 @@
 #include <__chrono/duration.h>
 #include <__chrono/file_clock.h>
 #include <__chrono/hh_mm_ss.h>
+#include <__chrono/local_info.h>
 #include <__chrono/month.h>
 #include <__chrono/month_weekday.h>
 #include <__chrono/monthday.h>
@@ -175,6 +176,8 @@ _LIBCPP_HIDE_FROM_ABI _Tm __convert_to_tm(const _ChronoT& 
__value) {
 #  if !defined(_LIBCPP_HAS_NO_INCOMPLETE_TZDB)
   } else if constexpr (same_as<_ChronoT, chrono::sys_info>) {
 // Has no time information.
+  } else if constexpr (same_as<_ChronoT, chrono::local_info>) {
+// Has no time information.
 #  endif
   } else
 static_assert(sizeof(_ChronoT) == 0, "Add the missing type 
specialization");
diff --git a/libcxx/include/__chrono/formatter.h 
b/libcxx/include/__chrono/formatter.h
index 79192fa103fbdb..a090eb0bfcc88a 100644
--- a/libcxx/include/__chrono/formatter.h
+++ b/libcxx/include/__chrono/formatter.h
@@ -18,6 +18,7 @@
 #include <__chrono/duration.h>
 #include <__chrono/file_clock.h>
 #include <__chrono/hh_mm_ss.h>
+#include <__chrono/local_info.h>
 #include <__chrono/month.h>
 #include <__chrono/month_weekday.h>
 #include <__chrono/monthday.h>
@@ -420,6 +421,8 @@ _LIBCPP_HIDE_FROM_ABI constexpr bool __weekday_ok(const 
_Tp& __value) {
 #  if !defined(_LIBCPP_HAS_NO_INCOMPLETE_TZDB)
   else if constexpr (same_as<_Tp, chrono::sys_info>)
 return true;
+  else if constexpr (same_as<_Tp, chrono::local_info>)
+return true;
 #  endif
   else
 static_assert(sizeof(_Tp) == 0, "Add the missing type specialization");
@@ -464,6 +467,8 @@ _LIBCPP_HIDE_FROM_ABI constexpr bool 
__weekday_name_ok(const _Tp& __value) {
 #  if 

[llvm-branch-commits] [libcxx] [libc++][TZDB] Adds local_info formatter. (PR #86256)

2024-03-22 Thread Mark de Wever via llvm-branch-commits

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

>From 358347b163202b27b724543727d7602b4c4a19a8 Mon Sep 17 00:00:00 2001
From: Mark de Wever 
Date: Thu, 14 Mar 2024 21:10:58 +0100
Subject: [PATCH] [libc++][TZDB] Adds local_info formatter.

Note the code using a local_info object will be done in a separate
commit.

Implements parts of:
- P0355 Extending to Calendars and Time Zones
- P1361 Integration of chrono with text formatting
---
 libcxx/docs/Status/FormatPaper.csv|   2 +-
 libcxx/include/CMakeLists.txt |   1 +
 libcxx/include/__chrono/convert_to_tm.h   |   3 +
 libcxx/include/__chrono/formatter.h   |  20 +++
 libcxx/include/__chrono/local_info.h  |  50 +++
 libcxx/include/__chrono/ostream.h |  22 +++
 libcxx/include/chrono |  16 +++
 libcxx/include/libcxx.imp |   1 +
 libcxx/include/module.modulemap   |   1 +
 libcxx/modules/std/chrono.inc |   1 +
 .../time.zone.info.local/ostream.pass.cpp | 114 
 .../time.syn/formatter.local_info.pass.cpp| 126 ++
 .../time.zone.info.local/ostream.pass.cpp |  51 +++
 13 files changed, 407 insertions(+), 1 deletion(-)
 create mode 100644 libcxx/include/__chrono/local_info.h
 create mode 100644 
libcxx/test/libcxx/time/time.zone/time.zone.info/time.zone.info.local/ostream.pass.cpp
 create mode 100644 libcxx/test/std/time/time.syn/formatter.local_info.pass.cpp
 create mode 100644 
libcxx/test/std/time/time.zone/time.zone.info/time.zone.info.local/ostream.pass.cpp

diff --git a/libcxx/docs/Status/FormatPaper.csv 
b/libcxx/docs/Status/FormatPaper.csv
index 32166ec72da753..b1a957c7b65dd1 100644
--- a/libcxx/docs/Status/FormatPaper.csv
+++ b/libcxx/docs/Status/FormatPaper.csv
@@ -25,7 +25,7 @@ Section,Description,Dependencies,Assignee,Status,First 
released version
 `[time.syn] `_,"Formatter 
``chrono::year_month_weekday_last``",,Mark de Wever,|Complete|,16.0
 `[time.syn] `_,"Formatter 
``chrono::hh_mm_ss>``",,Mark de Wever,|Complete|,17.0
 `[time.syn] `_,"Formatter 
``chrono::sys_info``",,Mark de Wever,|Complete|,19.0
-`[time.syn] `_,"Formatter 
``chrono::local_info``",A  implementation,Mark de Wever,,
+`[time.syn] `_,"Formatter 
``chrono::local_info``",,Mark de Wever,|Complete|,19.0
 `[time.syn] `_,"Formatter 
``chrono::zoned_time``",A  
implementation,Mark de Wever,,
 
 `P2286R8 `__,"Formatting ranges"
diff --git a/libcxx/include/CMakeLists.txt b/libcxx/include/CMakeLists.txt
index 2fc329d9e71457..a343e4c69c472c 100644
--- a/libcxx/include/CMakeLists.txt
+++ b/libcxx/include/CMakeLists.txt
@@ -283,6 +283,7 @@ set(files
   __chrono/high_resolution_clock.h
   __chrono/leap_second.h
   __chrono/literals.h
+  __chrono/local_info.h
   __chrono/month.h
   __chrono/month_weekday.h
   __chrono/monthday.h
diff --git a/libcxx/include/__chrono/convert_to_tm.h 
b/libcxx/include/__chrono/convert_to_tm.h
index d2c5cf922ba671..f7256db3bea661 100644
--- a/libcxx/include/__chrono/convert_to_tm.h
+++ b/libcxx/include/__chrono/convert_to_tm.h
@@ -16,6 +16,7 @@
 #include <__chrono/duration.h>
 #include <__chrono/file_clock.h>
 #include <__chrono/hh_mm_ss.h>
+#include <__chrono/local_info.h>
 #include <__chrono/month.h>
 #include <__chrono/month_weekday.h>
 #include <__chrono/monthday.h>
@@ -175,6 +176,8 @@ _LIBCPP_HIDE_FROM_ABI _Tm __convert_to_tm(const _ChronoT& 
__value) {
 #  if !defined(_LIBCPP_HAS_NO_INCOMPLETE_TZDB)
   } else if constexpr (same_as<_ChronoT, chrono::sys_info>) {
 // Has no time information.
+  } else if constexpr (same_as<_ChronoT, chrono::local_info>) {
+// Has no time information.
 #  endif
   } else
 static_assert(sizeof(_ChronoT) == 0, "Add the missing type 
specialization");
diff --git a/libcxx/include/__chrono/formatter.h 
b/libcxx/include/__chrono/formatter.h
index 79192fa103fbdb..a090eb0bfcc88a 100644
--- a/libcxx/include/__chrono/formatter.h
+++ b/libcxx/include/__chrono/formatter.h
@@ -18,6 +18,7 @@
 #include <__chrono/duration.h>
 #include <__chrono/file_clock.h>
 #include <__chrono/hh_mm_ss.h>
+#include <__chrono/local_info.h>
 #include <__chrono/month.h>
 #include <__chrono/month_weekday.h>
 #include <__chrono/monthday.h>
@@ -420,6 +421,8 @@ _LIBCPP_HIDE_FROM_ABI constexpr bool __weekday_ok(const 
_Tp& __value) {
 #  if !defined(_LIBCPP_HAS_NO_INCOMPLETE_TZDB)
   else if constexpr (same_as<_Tp, chrono::sys_info>)
 return true;
+  else if constexpr (same_as<_Tp, chrono::local_info>)
+return true;
 #  endif
   else
 static_assert(sizeof(_Tp) == 0, "Add the missing type specialization");
@@ -464,6 +467,8 @@ _LIBCPP_HIDE_FROM_ABI constexpr bool 
__weekday_name_ok(const _Tp& __value) {
 #  if 

[llvm-branch-commits] [libcxx] [libc++][TZDB] Adds local_info formatter. (PR #86256)

2024-03-22 Thread Mark de Wever via llvm-branch-commits

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

This adds the local_info type and its formatting options.
The usage of the local_info object will be done in separate patches.

Implements parts of:
- P0355 Extending to Calendars and Time Zones
- P1361 Integration of chrono with text formatting

>From 891e126cb98a4e8d1ced5b64830b7cd08397d850 Mon Sep 17 00:00:00 2001
From: Mark de Wever 
Date: Thu, 14 Mar 2024 21:10:58 +0100
Subject: [PATCH] [libc++][TZDB] Adds local_info formatter.

Note the code using a local_info object will be done in a separate
commit.

Implements parts of:
- P0355 Extending to Calendars and Time Zones
- P1361 Integration of chrono with text formatting
---
 libcxx/docs/Status/FormatPaper.csv|   2 +-
 libcxx/include/CMakeLists.txt |   1 +
 libcxx/include/__chrono/convert_to_tm.h   |   3 +
 libcxx/include/__chrono/formatter.h   |  20 +++
 libcxx/include/__chrono/local_info.h  |  50 +++
 libcxx/include/__chrono/ostream.h |  22 +++
 libcxx/include/chrono |  16 +++
 libcxx/include/libcxx.imp |   1 +
 libcxx/modules/std/chrono.inc |   1 +
 .../time.zone.info.local/ostream.pass.cpp | 114 
 .../time.syn/formatter.local_info.pass.cpp| 126 ++
 .../time.zone.info.local/ostream.pass.cpp |  51 +++
 12 files changed, 406 insertions(+), 1 deletion(-)
 create mode 100644 libcxx/include/__chrono/local_info.h
 create mode 100644 
libcxx/test/libcxx/time/time.zone/time.zone.info/time.zone.info.local/ostream.pass.cpp
 create mode 100644 libcxx/test/std/time/time.syn/formatter.local_info.pass.cpp
 create mode 100644 
libcxx/test/std/time/time.zone/time.zone.info/time.zone.info.local/ostream.pass.cpp

diff --git a/libcxx/docs/Status/FormatPaper.csv 
b/libcxx/docs/Status/FormatPaper.csv
index 32166ec72da753..b1a957c7b65dd1 100644
--- a/libcxx/docs/Status/FormatPaper.csv
+++ b/libcxx/docs/Status/FormatPaper.csv
@@ -25,7 +25,7 @@ Section,Description,Dependencies,Assignee,Status,First 
released version
 `[time.syn] `_,"Formatter 
``chrono::year_month_weekday_last``",,Mark de Wever,|Complete|,16.0
 `[time.syn] `_,"Formatter 
``chrono::hh_mm_ss>``",,Mark de Wever,|Complete|,17.0
 `[time.syn] `_,"Formatter 
``chrono::sys_info``",,Mark de Wever,|Complete|,19.0
-`[time.syn] `_,"Formatter 
``chrono::local_info``",A  implementation,Mark de Wever,,
+`[time.syn] `_,"Formatter 
``chrono::local_info``",,Mark de Wever,|Complete|,19.0
 `[time.syn] `_,"Formatter 
``chrono::zoned_time``",A  
implementation,Mark de Wever,,
 
 `P2286R8 `__,"Formatting ranges"
diff --git a/libcxx/include/CMakeLists.txt b/libcxx/include/CMakeLists.txt
index 2fc329d9e71457..a343e4c69c472c 100644
--- a/libcxx/include/CMakeLists.txt
+++ b/libcxx/include/CMakeLists.txt
@@ -283,6 +283,7 @@ set(files
   __chrono/high_resolution_clock.h
   __chrono/leap_second.h
   __chrono/literals.h
+  __chrono/local_info.h
   __chrono/month.h
   __chrono/month_weekday.h
   __chrono/monthday.h
diff --git a/libcxx/include/__chrono/convert_to_tm.h 
b/libcxx/include/__chrono/convert_to_tm.h
index d2c5cf922ba671..f7256db3bea661 100644
--- a/libcxx/include/__chrono/convert_to_tm.h
+++ b/libcxx/include/__chrono/convert_to_tm.h
@@ -16,6 +16,7 @@
 #include <__chrono/duration.h>
 #include <__chrono/file_clock.h>
 #include <__chrono/hh_mm_ss.h>
+#include <__chrono/local_info.h>
 #include <__chrono/month.h>
 #include <__chrono/month_weekday.h>
 #include <__chrono/monthday.h>
@@ -175,6 +176,8 @@ _LIBCPP_HIDE_FROM_ABI _Tm __convert_to_tm(const _ChronoT& 
__value) {
 #  if !defined(_LIBCPP_HAS_NO_INCOMPLETE_TZDB)
   } else if constexpr (same_as<_ChronoT, chrono::sys_info>) {
 // Has no time information.
+  } else if constexpr (same_as<_ChronoT, chrono::local_info>) {
+// Has no time information.
 #  endif
   } else
 static_assert(sizeof(_ChronoT) == 0, "Add the missing type 
specialization");
diff --git a/libcxx/include/__chrono/formatter.h 
b/libcxx/include/__chrono/formatter.h
index 79192fa103fbdb..a090eb0bfcc88a 100644
--- a/libcxx/include/__chrono/formatter.h
+++ b/libcxx/include/__chrono/formatter.h
@@ -18,6 +18,7 @@
 #include <__chrono/duration.h>
 #include <__chrono/file_clock.h>
 #include <__chrono/hh_mm_ss.h>
+#include <__chrono/local_info.h>
 #include <__chrono/month.h>
 #include <__chrono/month_weekday.h>
 #include <__chrono/monthday.h>
@@ -420,6 +421,8 @@ _LIBCPP_HIDE_FROM_ABI constexpr bool __weekday_ok(const 
_Tp& __value) {
 #  if !defined(_LIBCPP_HAS_NO_INCOMPLETE_TZDB)
   else if constexpr (same_as<_Tp, chrono::sys_info>)
 return true;
+  else if constexpr (same_as<_Tp, chrono::local_info>)
+return true;
 #  endif
   else
 

[llvm-branch-commits] [libcxx] release/18.x: Reapply [libcxx] [modules] Fix relative paths with absolute LIBCXX_INSTALL_MODULES_DIR (#86020) (PR #86197)

2024-03-21 Thread Mark de Wever via llvm-branch-commits

https://github.com/mordante approved this pull request.


https://github.com/llvm/llvm-project/pull/86197
___
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++][TZDB] Adds sys_info formatter. (PR #85896)

2024-03-21 Thread Mark de Wever via llvm-branch-commits

https://github.com/mordante edited 
https://github.com/llvm/llvm-project/pull/85896
___
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++][TZDB] Adds sys_info formatter. (PR #85896)

2024-03-21 Thread Mark de Wever via llvm-branch-commits

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

>From f3e7b583dd8eae59c3caeb84ac3967f361f6e6eb Mon Sep 17 00:00:00 2001
From: Mark de Wever 
Date: Thu, 21 Mar 2024 15:22:13 +0100
Subject: [PATCH 1/2] [libc++][chrono] Improves date formatting.

The formatting of years has been done manually since the results of %Y
outside the "typical" range may produce unexpected values. The same
applies to %F which is identical to %Y-%m-%d. Note of these conversion
specifiers is affected by the locale used. So it's trivial to manually
handle this case.

This removes several platform specific ifdefs from the tests.
---
 libcxx/include/__chrono/formatter.h   | 16 -
 .../time.cal.ymd.nonmembers/ostream.pass.cpp  | 34 ---
 .../sys_date.ostream.pass.cpp | 34 ---
 .../formatter.year_month_day.pass.cpp | 24 -
 4 files changed, 7 insertions(+), 101 deletions(-)

diff --git a/libcxx/include/__chrono/formatter.h 
b/libcxx/include/__chrono/formatter.h
index 8b8592041a1fb9..217979e88c93db 100644
--- a/libcxx/include/__chrono/formatter.h
+++ b/libcxx/include/__chrono/formatter.h
@@ -322,15 +322,13 @@ _LIBCPP_HIDE_FROM_ABI void 
__format_chrono_using_chrono_specs(
 __formatter::__format_year(__sstr, __t.tm_year + 1900);
 break;
 
-  case _CharT('F'): {
-int __year = __t.tm_year + 1900;
-if (__year < 1000) {
-  __formatter::__format_year(__sstr, __year);
-  __sstr << std::format(_LIBCPP_STATICALLY_WIDEN(_CharT, 
"-{:02}-{:02}"), __t.tm_mon + 1, __t.tm_mday);
-} else
-  __facet.put(
-  {__sstr}, __sstr, _CharT(' '), std::addressof(__t), 
std::to_address(__s), std::to_address(__it + 1));
-  } break;
+  case _CharT('F'):
+// Depending on the platform's libc the range of supported years is
+// limited. Intead of of testing all conditions use the internal
+// implementation unconditionally.
+__formatter::__format_year(__sstr, __t.tm_year + 1900);
+__sstr << std::format(_LIBCPP_STATICALLY_WIDEN(_CharT, 
"-{:02}-{:02}"), __t.tm_mon + 1, __t.tm_mday);
+break;
 
   case _CharT('z'):
 __formatter::__format_zone_offset(__sstr, __z.__offset, false);
diff --git 
a/libcxx/test/std/time/time.cal/time.cal.ymd/time.cal.ymd.nonmembers/ostream.pass.cpp
 
b/libcxx/test/std/time/time.cal/time.cal.ymd/time.cal.ymd.nonmembers/ostream.pass.cpp
index ffc737fcad5dd2..20ffb165558e31 100644
--- 
a/libcxx/test/std/time/time.cal/time.cal.ymd/time.cal.ymd.nonmembers/ostream.pass.cpp
+++ 
b/libcxx/test/std/time/time.cal/time.cal.ymd/time.cal.ymd.nonmembers/ostream.pass.cpp
@@ -13,9 +13,6 @@
 // TODO FMT This test should not require std::to_chars(floating-point)
 // XFAIL: availability-fp_to_chars-missing
 
-// TODO FMT Investigate Windows issues.
-// XFAIL: msvc
-
 // REQUIRES: locale.fr_FR.UTF-8
 // REQUIRES: locale.ja_JP.UTF-8
 
@@ -89,20 +86,9 @@ static void test() {
   TEST_EQUAL(stream_c_locale(
  std::chrono::year_month_day{std::chrono::year{2000}, 
std::chrono::month{2}, std::chrono::day{29}}),
  SV("2000-02-29"));
-
-#if defined(_AIX)
-  TEST_EQUAL(stream_c_locale(
- std::chrono::year_month_day{std::chrono::year{32'767}, 
std::chrono::month{12}, std::chrono::day{31}}),
- SV("+32767-12-31"));
-#elif defined(_WIN32) // defined(_AIX)
-  TEST_EQUAL(stream_c_locale(
- std::chrono::year_month_day{std::chrono::year{32'767}, 
std::chrono::month{12}, std::chrono::day{31}}),
- SV(""));
-#else //  defined(_AIX)
   TEST_EQUAL(stream_c_locale(
  std::chrono::year_month_day{std::chrono::year{32'767}, 
std::chrono::month{12}, std::chrono::day{31}}),
  SV("32767-12-31"));
-#endif// defined(_AIX)
 
   TEST_EQUAL(stream_fr_FR_locale(
  std::chrono::year_month_day{std::chrono::year{-32'768}, 
std::chrono::month{1}, std::chrono::day{1}}),
@@ -122,19 +108,9 @@ static void test() {
   TEST_EQUAL(stream_fr_FR_locale(
  std::chrono::year_month_day{std::chrono::year{2000}, 
std::chrono::month{2}, std::chrono::day{29}}),
  SV("2000-02-29"));
-#if defined(_AIX)
-  TEST_EQUAL(stream_fr_FR_locale(
- std::chrono::year_month_day{std::chrono::year{32'767}, 
std::chrono::month{12}, std::chrono::day{31}}),
- SV("+32767-12-31"));
-#elif defined(_WIN32) // defined(_AIX)
-  TEST_EQUAL(stream_fr_FR_locale(
- std::chrono::year_month_day{std::chrono::year{32'767}, 
std::chrono::month{12}, std::chrono::day{31}}),
- SV(""));
-#else // defined(_AIX)
   TEST_EQUAL(stream_fr_FR_locale(
  std::chrono::year_month_day{std::chrono::year{32'767}, 
std::chrono::month{12}, std::chrono::day{31}}),
  SV("32767-12-31"));
-#endif// defined(_AIX)
 
   

[llvm-branch-commits] [libcxx] [libc++][chrono] Improves date formatting. (PR #86127)

2024-03-21 Thread Mark de Wever via llvm-branch-commits

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

>From f3e7b583dd8eae59c3caeb84ac3967f361f6e6eb Mon Sep 17 00:00:00 2001
From: Mark de Wever 
Date: Thu, 21 Mar 2024 15:22:13 +0100
Subject: [PATCH] [libc++][chrono] Improves date formatting.

The formatting of years has been done manually since the results of %Y
outside the "typical" range may produce unexpected values. The same
applies to %F which is identical to %Y-%m-%d. Note of these conversion
specifiers is affected by the locale used. So it's trivial to manually
handle this case.

This removes several platform specific ifdefs from the tests.
---
 libcxx/include/__chrono/formatter.h   | 16 -
 .../time.cal.ymd.nonmembers/ostream.pass.cpp  | 34 ---
 .../sys_date.ostream.pass.cpp | 34 ---
 .../formatter.year_month_day.pass.cpp | 24 -
 4 files changed, 7 insertions(+), 101 deletions(-)

diff --git a/libcxx/include/__chrono/formatter.h 
b/libcxx/include/__chrono/formatter.h
index 8b8592041a1fb9..217979e88c93db 100644
--- a/libcxx/include/__chrono/formatter.h
+++ b/libcxx/include/__chrono/formatter.h
@@ -322,15 +322,13 @@ _LIBCPP_HIDE_FROM_ABI void 
__format_chrono_using_chrono_specs(
 __formatter::__format_year(__sstr, __t.tm_year + 1900);
 break;
 
-  case _CharT('F'): {
-int __year = __t.tm_year + 1900;
-if (__year < 1000) {
-  __formatter::__format_year(__sstr, __year);
-  __sstr << std::format(_LIBCPP_STATICALLY_WIDEN(_CharT, 
"-{:02}-{:02}"), __t.tm_mon + 1, __t.tm_mday);
-} else
-  __facet.put(
-  {__sstr}, __sstr, _CharT(' '), std::addressof(__t), 
std::to_address(__s), std::to_address(__it + 1));
-  } break;
+  case _CharT('F'):
+// Depending on the platform's libc the range of supported years is
+// limited. Intead of of testing all conditions use the internal
+// implementation unconditionally.
+__formatter::__format_year(__sstr, __t.tm_year + 1900);
+__sstr << std::format(_LIBCPP_STATICALLY_WIDEN(_CharT, 
"-{:02}-{:02}"), __t.tm_mon + 1, __t.tm_mday);
+break;
 
   case _CharT('z'):
 __formatter::__format_zone_offset(__sstr, __z.__offset, false);
diff --git 
a/libcxx/test/std/time/time.cal/time.cal.ymd/time.cal.ymd.nonmembers/ostream.pass.cpp
 
b/libcxx/test/std/time/time.cal/time.cal.ymd/time.cal.ymd.nonmembers/ostream.pass.cpp
index ffc737fcad5dd2..20ffb165558e31 100644
--- 
a/libcxx/test/std/time/time.cal/time.cal.ymd/time.cal.ymd.nonmembers/ostream.pass.cpp
+++ 
b/libcxx/test/std/time/time.cal/time.cal.ymd/time.cal.ymd.nonmembers/ostream.pass.cpp
@@ -13,9 +13,6 @@
 // TODO FMT This test should not require std::to_chars(floating-point)
 // XFAIL: availability-fp_to_chars-missing
 
-// TODO FMT Investigate Windows issues.
-// XFAIL: msvc
-
 // REQUIRES: locale.fr_FR.UTF-8
 // REQUIRES: locale.ja_JP.UTF-8
 
@@ -89,20 +86,9 @@ static void test() {
   TEST_EQUAL(stream_c_locale(
  std::chrono::year_month_day{std::chrono::year{2000}, 
std::chrono::month{2}, std::chrono::day{29}}),
  SV("2000-02-29"));
-
-#if defined(_AIX)
-  TEST_EQUAL(stream_c_locale(
- std::chrono::year_month_day{std::chrono::year{32'767}, 
std::chrono::month{12}, std::chrono::day{31}}),
- SV("+32767-12-31"));
-#elif defined(_WIN32) // defined(_AIX)
-  TEST_EQUAL(stream_c_locale(
- std::chrono::year_month_day{std::chrono::year{32'767}, 
std::chrono::month{12}, std::chrono::day{31}}),
- SV(""));
-#else //  defined(_AIX)
   TEST_EQUAL(stream_c_locale(
  std::chrono::year_month_day{std::chrono::year{32'767}, 
std::chrono::month{12}, std::chrono::day{31}}),
  SV("32767-12-31"));
-#endif// defined(_AIX)
 
   TEST_EQUAL(stream_fr_FR_locale(
  std::chrono::year_month_day{std::chrono::year{-32'768}, 
std::chrono::month{1}, std::chrono::day{1}}),
@@ -122,19 +108,9 @@ static void test() {
   TEST_EQUAL(stream_fr_FR_locale(
  std::chrono::year_month_day{std::chrono::year{2000}, 
std::chrono::month{2}, std::chrono::day{29}}),
  SV("2000-02-29"));
-#if defined(_AIX)
-  TEST_EQUAL(stream_fr_FR_locale(
- std::chrono::year_month_day{std::chrono::year{32'767}, 
std::chrono::month{12}, std::chrono::day{31}}),
- SV("+32767-12-31"));
-#elif defined(_WIN32) // defined(_AIX)
-  TEST_EQUAL(stream_fr_FR_locale(
- std::chrono::year_month_day{std::chrono::year{32'767}, 
std::chrono::month{12}, std::chrono::day{31}}),
- SV(""));
-#else // defined(_AIX)
   TEST_EQUAL(stream_fr_FR_locale(
  std::chrono::year_month_day{std::chrono::year{32'767}, 
std::chrono::month{12}, std::chrono::day{31}}),
  SV("32767-12-31"));
-#endif// defined(_AIX)
 
   

[llvm-branch-commits] [libcxx] [libc++][chrono] Improves date formatting. (PR #86127)

2024-03-21 Thread Mark de Wever via llvm-branch-commits

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

The formatting of years has been done manually since the results of %Y outside 
the "typical" range may produce unexpected values. The same applies to %F which 
is identical to %Y-%m-%d. Note of these conversion specifiers is affected by 
the locale used. So it's trivial to manually handle this case.

This removes several platform specific ifdefs from the tests.

>From 0aeab5a82110d6e3d01fb8c8562f5569c84203a3 Mon Sep 17 00:00:00 2001
From: Mark de Wever 
Date: Thu, 21 Mar 2024 15:22:13 +0100
Subject: [PATCH] [libc++][chrono] Improves date formatting.

The formatting of years has been done manually since the results of %Y
outside the "typical" range may produce unexpected values. The same
applies to %F which is identical to %Y-%m-%d. Note of these conversion
specifiers is affected by the locale used. So it's trivial to manually
handle this case.

This removes several platform specific ifdefs from the tests.
---
 libcxx/include/__chrono/formatter.h   | 16 +-
 .../time.cal.ymd.nonmembers/ostream.pass.cpp  | 31 ---
 .../sys_date.ostream.pass.cpp | 31 ---
 .../formatter.year_month_day.pass.cpp | 24 --
 4 files changed, 7 insertions(+), 95 deletions(-)

diff --git a/libcxx/include/__chrono/formatter.h 
b/libcxx/include/__chrono/formatter.h
index 8b8592041a1fb9..217979e88c93db 100644
--- a/libcxx/include/__chrono/formatter.h
+++ b/libcxx/include/__chrono/formatter.h
@@ -322,15 +322,13 @@ _LIBCPP_HIDE_FROM_ABI void 
__format_chrono_using_chrono_specs(
 __formatter::__format_year(__sstr, __t.tm_year + 1900);
 break;
 
-  case _CharT('F'): {
-int __year = __t.tm_year + 1900;
-if (__year < 1000) {
-  __formatter::__format_year(__sstr, __year);
-  __sstr << std::format(_LIBCPP_STATICALLY_WIDEN(_CharT, 
"-{:02}-{:02}"), __t.tm_mon + 1, __t.tm_mday);
-} else
-  __facet.put(
-  {__sstr}, __sstr, _CharT(' '), std::addressof(__t), 
std::to_address(__s), std::to_address(__it + 1));
-  } break;
+  case _CharT('F'):
+// Depending on the platform's libc the range of supported years is
+// limited. Intead of of testing all conditions use the internal
+// implementation unconditionally.
+__formatter::__format_year(__sstr, __t.tm_year + 1900);
+__sstr << std::format(_LIBCPP_STATICALLY_WIDEN(_CharT, 
"-{:02}-{:02}"), __t.tm_mon + 1, __t.tm_mday);
+break;
 
   case _CharT('z'):
 __formatter::__format_zone_offset(__sstr, __z.__offset, false);
diff --git 
a/libcxx/test/std/time/time.cal/time.cal.ymd/time.cal.ymd.nonmembers/ostream.pass.cpp
 
b/libcxx/test/std/time/time.cal/time.cal.ymd/time.cal.ymd.nonmembers/ostream.pass.cpp
index ffc737fcad5dd2..3a37e75bbcd2e4 100644
--- 
a/libcxx/test/std/time/time.cal/time.cal.ymd/time.cal.ymd.nonmembers/ostream.pass.cpp
+++ 
b/libcxx/test/std/time/time.cal/time.cal.ymd/time.cal.ymd.nonmembers/ostream.pass.cpp
@@ -89,20 +89,9 @@ static void test() {
   TEST_EQUAL(stream_c_locale(
  std::chrono::year_month_day{std::chrono::year{2000}, 
std::chrono::month{2}, std::chrono::day{29}}),
  SV("2000-02-29"));
-
-#if defined(_AIX)
-  TEST_EQUAL(stream_c_locale(
- std::chrono::year_month_day{std::chrono::year{32'767}, 
std::chrono::month{12}, std::chrono::day{31}}),
- SV("+32767-12-31"));
-#elif defined(_WIN32) // defined(_AIX)
-  TEST_EQUAL(stream_c_locale(
- std::chrono::year_month_day{std::chrono::year{32'767}, 
std::chrono::month{12}, std::chrono::day{31}}),
- SV(""));
-#else //  defined(_AIX)
   TEST_EQUAL(stream_c_locale(
  std::chrono::year_month_day{std::chrono::year{32'767}, 
std::chrono::month{12}, std::chrono::day{31}}),
  SV("32767-12-31"));
-#endif// defined(_AIX)
 
   TEST_EQUAL(stream_fr_FR_locale(
  std::chrono::year_month_day{std::chrono::year{-32'768}, 
std::chrono::month{1}, std::chrono::day{1}}),
@@ -122,19 +111,9 @@ static void test() {
   TEST_EQUAL(stream_fr_FR_locale(
  std::chrono::year_month_day{std::chrono::year{2000}, 
std::chrono::month{2}, std::chrono::day{29}}),
  SV("2000-02-29"));
-#if defined(_AIX)
-  TEST_EQUAL(stream_fr_FR_locale(
- std::chrono::year_month_day{std::chrono::year{32'767}, 
std::chrono::month{12}, std::chrono::day{31}}),
- SV("+32767-12-31"));
-#elif defined(_WIN32) // defined(_AIX)
-  TEST_EQUAL(stream_fr_FR_locale(
- std::chrono::year_month_day{std::chrono::year{32'767}, 
std::chrono::month{12}, std::chrono::day{31}}),
- SV(""));
-#else // defined(_AIX)
   TEST_EQUAL(stream_fr_FR_locale(
  std::chrono::year_month_day{std::chrono::year{32'767}, 
std::chrono::month{12}, 

[llvm-branch-commits] [libcxx] [libc++][TZDB] Adds sys_info formatter. (PR #85896)

2024-03-21 Thread Mark de Wever via llvm-branch-commits

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

>From 3eaa059039c7fe9ea4b5fdaadacac7d9c8fa5f3f Mon Sep 17 00:00:00 2001
From: Mark de Wever 
Date: Sun, 10 Mar 2024 17:49:39 +0100
Subject: [PATCH] [libc++][TZDB] Adds sys_info formatter.

Implements parts of:
- P0355 Extending  to Calendars and Time Zones
- P1361 Integration of chrono with text formatting
---
 libcxx/docs/Status/FormatPaper.csv|   2 +-
 libcxx/include/__chrono/convert_to_tm.h   |   5 +
 libcxx/include/__chrono/formatter.h   |  60 ++--
 libcxx/include/__chrono/ostream.h |  20 +++
 libcxx/include/__chrono/sys_info.h|   6 +-
 libcxx/include/chrono |   7 +-
 .../time.zone.info.sys/ostream.pass.cpp   |  74 ++
 .../test/libcxx/transitive_includes/cxx23.csv |   1 -
 .../test/libcxx/transitive_includes/cxx26.csv |   1 -
 .../time/time.syn/formatter.sys_info.pass.cpp | 137 ++
 .../time.zone.info.sys/ostream.pass.cpp   |  52 +++
 11 files changed, 345 insertions(+), 20 deletions(-)
 create mode 100644 
libcxx/test/libcxx/time/time.zone/time.zone.info/time.zone.info.sys/ostream.pass.cpp
 create mode 100644 libcxx/test/std/time/time.syn/formatter.sys_info.pass.cpp
 create mode 100644 
libcxx/test/std/time/time.zone/time.zone.info/time.zone.info.sys/ostream.pass.cpp

diff --git a/libcxx/docs/Status/FormatPaper.csv 
b/libcxx/docs/Status/FormatPaper.csv
index 82da54284c7386..32166ec72da753 100644
--- a/libcxx/docs/Status/FormatPaper.csv
+++ b/libcxx/docs/Status/FormatPaper.csv
@@ -24,7 +24,7 @@ Section,Description,Dependencies,Assignee,Status,First 
released version
 `[time.syn] `_,"Formatter 
``chrono::year_month_weekday``",,Mark de Wever,|Complete|,16.0
 `[time.syn] `_,"Formatter 
``chrono::year_month_weekday_last``",,Mark de Wever,|Complete|,16.0
 `[time.syn] `_,"Formatter 
``chrono::hh_mm_ss>``",,Mark de Wever,|Complete|,17.0
-`[time.syn] `_,"Formatter ``chrono::sys_info``",A 
 implementation,Mark de Wever,,
+`[time.syn] `_,"Formatter 
``chrono::sys_info``",,Mark de Wever,|Complete|,19.0
 `[time.syn] `_,"Formatter 
``chrono::local_info``",A  implementation,Mark de Wever,,
 `[time.syn] `_,"Formatter 
``chrono::zoned_time``",A  
implementation,Mark de Wever,,
 
diff --git a/libcxx/include/__chrono/convert_to_tm.h 
b/libcxx/include/__chrono/convert_to_tm.h
index 1301cd6f1f1ada..d2c5cf922ba671 100644
--- a/libcxx/include/__chrono/convert_to_tm.h
+++ b/libcxx/include/__chrono/convert_to_tm.h
@@ -20,6 +20,7 @@
 #include <__chrono/month_weekday.h>
 #include <__chrono/monthday.h>
 #include <__chrono/statically_widen.h>
+#include <__chrono/sys_info.h>
 #include <__chrono/system_clock.h>
 #include <__chrono/time_point.h>
 #include <__chrono/weekday.h>
@@ -171,6 +172,10 @@ _LIBCPP_HIDE_FROM_ABI _Tm __convert_to_tm(const _ChronoT& 
__value) {
   if (__value.hours().count() > 
std::numeric_limits::max())
 std::__throw_format_error("Formatting hh_mm_ss, encountered an hour 
overflow");
 __result.tm_hour = __value.hours().count();
+#  if !defined(_LIBCPP_HAS_NO_INCOMPLETE_TZDB)
+  } else if constexpr (same_as<_ChronoT, chrono::sys_info>) {
+// Has no time information.
+#  endif
   } else
 static_assert(sizeof(_ChronoT) == 0, "Add the missing type 
specialization");
 
diff --git a/libcxx/include/__chrono/formatter.h 
b/libcxx/include/__chrono/formatter.h
index 8b8592041a1fb9..79192fa103fbdb 100644
--- a/libcxx/include/__chrono/formatter.h
+++ b/libcxx/include/__chrono/formatter.h
@@ -24,6 +24,7 @@
 #include <__chrono/ostream.h>
 #include <__chrono/parser_std_format_spec.h>
 #include <__chrono/statically_widen.h>
+#include <__chrono/sys_info.h>
 #include <__chrono/system_clock.h>
 #include <__chrono/time_point.h>
 #include <__chrono/weekday.h>
@@ -185,10 +186,11 @@ __format_zone_offset(basic_stringstream<_CharT>& __sstr, 
chrono::seconds __offse
 
   chrono::hh_mm_ss __hms{__offset};
   std::ostreambuf_iterator<_CharT> __out_it{__sstr};
+  // Note HMS does not allow formatting hours > 23, but the offset is not 
limited to 24H.
+  std::format_to(__out_it, _LIBCPP_STATICALLY_WIDEN(_CharT, "{:02}"), 
__hms.hours().count());
   if (__modifier)
-std::format_to(__out_it, _LIBCPP_STATICALLY_WIDEN(_CharT, "{:%H:%M}"), 
__hms);
-  else
-std::format_to(__out_it, _LIBCPP_STATICALLY_WIDEN(_CharT, "{:%H%M}"), 
__hms);
+__sstr << _CharT(':');
+  std::format_to(__out_it, _LIBCPP_STATICALLY_WIDEN(_CharT, "{:02}"), 
__hms.minutes().count());
 }
 
 // Helper to store the time zone information needed for formatting.
@@ -202,6 +204,12 @@ struct _LIBCPP_HIDE_FROM_ABI __time_zone {
 template 
 _LIBCPP_HIDE_FROM_ABI __time_zone __convert_to_time_zone([[maybe_unused]] 
const _Tp& __value) {
   

[llvm-branch-commits] [libcxx] [libc++][TZDB] Adds sys_info formatter. (PR #85896)

2024-03-21 Thread Mark de Wever via llvm-branch-commits

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

>From c17bb85f4863f1fffa8654b4e1931dfebc430e2d Mon Sep 17 00:00:00 2001
From: Mark de Wever 
Date: Sun, 10 Mar 2024 17:49:39 +0100
Subject: [PATCH] [libc++][TZDB] Adds sys_info formatter.

Implements parts of:
- P0355 Extending  to Calendars and Time Zones
- P1361 Integration of chrono with text formatting
---
 libcxx/docs/Status/FormatPaper.csv|   2 +-
 libcxx/include/__chrono/convert_to_tm.h   |   5 +
 libcxx/include/__chrono/formatter.h   |  58 ++--
 libcxx/include/__chrono/ostream.h |  20 +++
 libcxx/include/__chrono/sys_info.h|   6 +-
 libcxx/include/chrono |   7 +-
 .../time.zone.info.sys/ostream.pass.cpp   |  74 ++
 .../test/libcxx/transitive_includes/cxx23.csv |   1 -
 .../test/libcxx/transitive_includes/cxx26.csv |   1 -
 .../time/time.syn/formatter.sys_info.pass.cpp | 137 ++
 .../time.zone.info.sys/ostream.pass.cpp   |  52 +++
 11 files changed, 344 insertions(+), 19 deletions(-)
 create mode 100644 
libcxx/test/libcxx/time/time.zone/time.zone.info/time.zone.info.sys/ostream.pass.cpp
 create mode 100644 libcxx/test/std/time/time.syn/formatter.sys_info.pass.cpp
 create mode 100644 
libcxx/test/std/time/time.zone/time.zone.info/time.zone.info.sys/ostream.pass.cpp

diff --git a/libcxx/docs/Status/FormatPaper.csv 
b/libcxx/docs/Status/FormatPaper.csv
index 82da54284c7386..32166ec72da753 100644
--- a/libcxx/docs/Status/FormatPaper.csv
+++ b/libcxx/docs/Status/FormatPaper.csv
@@ -24,7 +24,7 @@ Section,Description,Dependencies,Assignee,Status,First 
released version
 `[time.syn] `_,"Formatter 
``chrono::year_month_weekday``",,Mark de Wever,|Complete|,16.0
 `[time.syn] `_,"Formatter 
``chrono::year_month_weekday_last``",,Mark de Wever,|Complete|,16.0
 `[time.syn] `_,"Formatter 
``chrono::hh_mm_ss>``",,Mark de Wever,|Complete|,17.0
-`[time.syn] `_,"Formatter ``chrono::sys_info``",A 
 implementation,Mark de Wever,,
+`[time.syn] `_,"Formatter 
``chrono::sys_info``",,Mark de Wever,|Complete|,19.0
 `[time.syn] `_,"Formatter 
``chrono::local_info``",A  implementation,Mark de Wever,,
 `[time.syn] `_,"Formatter 
``chrono::zoned_time``",A  
implementation,Mark de Wever,,
 
diff --git a/libcxx/include/__chrono/convert_to_tm.h 
b/libcxx/include/__chrono/convert_to_tm.h
index 1301cd6f1f1ada..d2c5cf922ba671 100644
--- a/libcxx/include/__chrono/convert_to_tm.h
+++ b/libcxx/include/__chrono/convert_to_tm.h
@@ -20,6 +20,7 @@
 #include <__chrono/month_weekday.h>
 #include <__chrono/monthday.h>
 #include <__chrono/statically_widen.h>
+#include <__chrono/sys_info.h>
 #include <__chrono/system_clock.h>
 #include <__chrono/time_point.h>
 #include <__chrono/weekday.h>
@@ -171,6 +172,10 @@ _LIBCPP_HIDE_FROM_ABI _Tm __convert_to_tm(const _ChronoT& 
__value) {
   if (__value.hours().count() > 
std::numeric_limits::max())
 std::__throw_format_error("Formatting hh_mm_ss, encountered an hour 
overflow");
 __result.tm_hour = __value.hours().count();
+#  if !defined(_LIBCPP_HAS_NO_INCOMPLETE_TZDB)
+  } else if constexpr (same_as<_ChronoT, chrono::sys_info>) {
+// Has no time information.
+#  endif
   } else
 static_assert(sizeof(_ChronoT) == 0, "Add the missing type 
specialization");
 
diff --git a/libcxx/include/__chrono/formatter.h 
b/libcxx/include/__chrono/formatter.h
index 8b8592041a1fb9..98976e20b1c820 100644
--- a/libcxx/include/__chrono/formatter.h
+++ b/libcxx/include/__chrono/formatter.h
@@ -24,6 +24,7 @@
 #include <__chrono/ostream.h>
 #include <__chrono/parser_std_format_spec.h>
 #include <__chrono/statically_widen.h>
+#include <__chrono/sys_info.h>
 #include <__chrono/system_clock.h>
 #include <__chrono/time_point.h>
 #include <__chrono/weekday.h>
@@ -185,10 +186,11 @@ __format_zone_offset(basic_stringstream<_CharT>& __sstr, 
chrono::seconds __offse
 
   chrono::hh_mm_ss __hms{__offset};
   std::ostreambuf_iterator<_CharT> __out_it{__sstr};
+  // Note HMS does not allow formatting hours > 23, but the offset is not 
limited to 24H.
+  std::format_to(__out_it, _LIBCPP_STATICALLY_WIDEN(_CharT, "{:02}"), 
__hms.hours().count());
   if (__modifier)
-std::format_to(__out_it, _LIBCPP_STATICALLY_WIDEN(_CharT, "{:%H:%M}"), 
__hms);
-  else
-std::format_to(__out_it, _LIBCPP_STATICALLY_WIDEN(_CharT, "{:%H%M}"), 
__hms);
+__sstr << _CharT(':');
+  std::format_to(__out_it, _LIBCPP_STATICALLY_WIDEN(_CharT, "{:02}"), 
__hms.minutes().count());
 }
 
 // Helper to store the time zone information needed for formatting.
@@ -202,6 +204,12 @@ struct _LIBCPP_HIDE_FROM_ABI __time_zone {
 template 
 _LIBCPP_HIDE_FROM_ABI __time_zone __convert_to_time_zone([[maybe_unused]] 
const _Tp& __value) {
   

[llvm-branch-commits] [libcxx] [libc++][TZDB] Adds sys_info formatter. (PR #85896)

2024-03-20 Thread Mark de Wever via llvm-branch-commits

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

>From 1c5788302b38da71881854bbee772e3ad8d58cb4 Mon Sep 17 00:00:00 2001
From: Mark de Wever 
Date: Sun, 10 Mar 2024 17:49:39 +0100
Subject: [PATCH] [libc++][TZDB] Adds sys_info formatter.

Implements parts of:
- P0355 Extending  to Calendars and Time Zones
- P1361 Integration of chrono with text formatting
---
 libcxx/docs/Status/FormatPaper.csv|   2 +-
 libcxx/include/__chrono/convert_to_tm.h   |   5 +
 libcxx/include/__chrono/formatter.h   |  44 +-
 libcxx/include/__chrono/ostream.h |  20 +++
 libcxx/include/__chrono/sys_info.h|   6 +-
 libcxx/include/chrono |   7 +-
 .../time.zone.info.sys/ostream.pass.cpp   |  74 ++
 .../test/libcxx/transitive_includes/cxx23.csv |   1 -
 .../test/libcxx/transitive_includes/cxx26.csv |   1 -
 .../time/time.syn/formatter.sys_info.pass.cpp | 137 ++
 .../time.zone.info.sys/ostream.pass.cpp   |  52 +++
 11 files changed, 338 insertions(+), 11 deletions(-)
 create mode 100644 
libcxx/test/libcxx/time/time.zone/time.zone.info/time.zone.info.sys/ostream.pass.cpp
 create mode 100644 libcxx/test/std/time/time.syn/formatter.sys_info.pass.cpp
 create mode 100644 
libcxx/test/std/time/time.zone/time.zone.info/time.zone.info.sys/ostream.pass.cpp

diff --git a/libcxx/docs/Status/FormatPaper.csv 
b/libcxx/docs/Status/FormatPaper.csv
index 82da54284c7386..32166ec72da753 100644
--- a/libcxx/docs/Status/FormatPaper.csv
+++ b/libcxx/docs/Status/FormatPaper.csv
@@ -24,7 +24,7 @@ Section,Description,Dependencies,Assignee,Status,First 
released version
 `[time.syn] `_,"Formatter 
``chrono::year_month_weekday``",,Mark de Wever,|Complete|,16.0
 `[time.syn] `_,"Formatter 
``chrono::year_month_weekday_last``",,Mark de Wever,|Complete|,16.0
 `[time.syn] `_,"Formatter 
``chrono::hh_mm_ss>``",,Mark de Wever,|Complete|,17.0
-`[time.syn] `_,"Formatter ``chrono::sys_info``",A 
 implementation,Mark de Wever,,
+`[time.syn] `_,"Formatter 
``chrono::sys_info``",,Mark de Wever,|Complete|,19.0
 `[time.syn] `_,"Formatter 
``chrono::local_info``",A  implementation,Mark de Wever,,
 `[time.syn] `_,"Formatter 
``chrono::zoned_time``",A  
implementation,Mark de Wever,,
 
diff --git a/libcxx/include/__chrono/convert_to_tm.h 
b/libcxx/include/__chrono/convert_to_tm.h
index 1301cd6f1f1ada..d2c5cf922ba671 100644
--- a/libcxx/include/__chrono/convert_to_tm.h
+++ b/libcxx/include/__chrono/convert_to_tm.h
@@ -20,6 +20,7 @@
 #include <__chrono/month_weekday.h>
 #include <__chrono/monthday.h>
 #include <__chrono/statically_widen.h>
+#include <__chrono/sys_info.h>
 #include <__chrono/system_clock.h>
 #include <__chrono/time_point.h>
 #include <__chrono/weekday.h>
@@ -171,6 +172,10 @@ _LIBCPP_HIDE_FROM_ABI _Tm __convert_to_tm(const _ChronoT& 
__value) {
   if (__value.hours().count() > 
std::numeric_limits::max())
 std::__throw_format_error("Formatting hh_mm_ss, encountered an hour 
overflow");
 __result.tm_hour = __value.hours().count();
+#  if !defined(_LIBCPP_HAS_NO_INCOMPLETE_TZDB)
+  } else if constexpr (same_as<_ChronoT, chrono::sys_info>) {
+// Has no time information.
+#  endif
   } else
 static_assert(sizeof(_ChronoT) == 0, "Add the missing type 
specialization");
 
diff --git a/libcxx/include/__chrono/formatter.h 
b/libcxx/include/__chrono/formatter.h
index 8b8592041a1fb9..6a9f5870458b32 100644
--- a/libcxx/include/__chrono/formatter.h
+++ b/libcxx/include/__chrono/formatter.h
@@ -24,6 +24,7 @@
 #include <__chrono/ostream.h>
 #include <__chrono/parser_std_format_spec.h>
 #include <__chrono/statically_widen.h>
+#include <__chrono/sys_info.h>
 #include <__chrono/system_clock.h>
 #include <__chrono/time_point.h>
 #include <__chrono/weekday.h>
@@ -185,10 +186,11 @@ __format_zone_offset(basic_stringstream<_CharT>& __sstr, 
chrono::seconds __offse
 
   chrono::hh_mm_ss __hms{__offset};
   std::ostreambuf_iterator<_CharT> __out_it{__sstr};
+  // Note HMS does not allow formatting hours > 23, but the offset is not 
limited to 24H.
+  std::format_to(__out_it, _LIBCPP_STATICALLY_WIDEN(_CharT, "{:02}"), 
__hms.hours().count());
   if (__modifier)
-std::format_to(__out_it, _LIBCPP_STATICALLY_WIDEN(_CharT, "{:%H:%M}"), 
__hms);
-  else
-std::format_to(__out_it, _LIBCPP_STATICALLY_WIDEN(_CharT, "{:%H%M}"), 
__hms);
+__sstr << _CharT(':');
+  std::format_to(__out_it, _LIBCPP_STATICALLY_WIDEN(_CharT, "{:02}"), 
__hms.minutes().count());
 }
 
 // Helper to store the time zone information needed for formatting.
@@ -202,6 +204,12 @@ struct _LIBCPP_HIDE_FROM_ABI __time_zone {
 template 
 _LIBCPP_HIDE_FROM_ABI __time_zone __convert_to_time_zone([[maybe_unused]] 
const _Tp& __value) {
   __time_zone 

[llvm-branch-commits] [libcxx] [libc++][TZDB] Adds sys_info formatter. (PR #85896)

2024-03-20 Thread Mark de Wever via llvm-branch-commits

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

>From caa67f946d7128ebe63c859ed7aa9a03c825e81e Mon Sep 17 00:00:00 2001
From: Mark de Wever 
Date: Sun, 10 Mar 2024 17:49:39 +0100
Subject: [PATCH] [libc++][TZDB] Adds sys_info formatter.

Implements parts of:
- P0355 Extending  to Calendars and Time Zones
- P1361 Integration of chrono with text formatting
---
 libcxx/docs/Status/FormatPaper.csv|   2 +-
 libcxx/include/__chrono/convert_to_tm.h   |   5 +
 libcxx/include/__chrono/formatter.h   |  44 +-
 libcxx/include/__chrono/ostream.h |  20 +++
 libcxx/include/__chrono/sys_info.h|   6 +-
 libcxx/include/chrono |   5 +
 .../time.zone.info.sys/ostream.pass.cpp   |  71 +
 .../test/libcxx/transitive_includes/cxx23.csv |   1 -
 .../test/libcxx/transitive_includes/cxx26.csv |   1 -
 .../time/time.syn/formatter.sys_info.pass.cpp | 137 ++
 .../time.zone.info.sys/ostream.pass.cpp   |  49 +++
 11 files changed, 331 insertions(+), 10 deletions(-)
 create mode 100644 
libcxx/test/libcxx/time/time.zone/time.zone.info/time.zone.info.sys/ostream.pass.cpp
 create mode 100644 libcxx/test/std/time/time.syn/formatter.sys_info.pass.cpp
 create mode 100644 
libcxx/test/std/time/time.zone/time.zone.info/time.zone.info.sys/ostream.pass.cpp

diff --git a/libcxx/docs/Status/FormatPaper.csv 
b/libcxx/docs/Status/FormatPaper.csv
index 82da54284c7386..32166ec72da753 100644
--- a/libcxx/docs/Status/FormatPaper.csv
+++ b/libcxx/docs/Status/FormatPaper.csv
@@ -24,7 +24,7 @@ Section,Description,Dependencies,Assignee,Status,First 
released version
 `[time.syn] `_,"Formatter 
``chrono::year_month_weekday``",,Mark de Wever,|Complete|,16.0
 `[time.syn] `_,"Formatter 
``chrono::year_month_weekday_last``",,Mark de Wever,|Complete|,16.0
 `[time.syn] `_,"Formatter 
``chrono::hh_mm_ss>``",,Mark de Wever,|Complete|,17.0
-`[time.syn] `_,"Formatter ``chrono::sys_info``",A 
 implementation,Mark de Wever,,
+`[time.syn] `_,"Formatter 
``chrono::sys_info``",,Mark de Wever,|Complete|,19.0
 `[time.syn] `_,"Formatter 
``chrono::local_info``",A  implementation,Mark de Wever,,
 `[time.syn] `_,"Formatter 
``chrono::zoned_time``",A  
implementation,Mark de Wever,,
 
diff --git a/libcxx/include/__chrono/convert_to_tm.h 
b/libcxx/include/__chrono/convert_to_tm.h
index 1301cd6f1f1ada..d2c5cf922ba671 100644
--- a/libcxx/include/__chrono/convert_to_tm.h
+++ b/libcxx/include/__chrono/convert_to_tm.h
@@ -20,6 +20,7 @@
 #include <__chrono/month_weekday.h>
 #include <__chrono/monthday.h>
 #include <__chrono/statically_widen.h>
+#include <__chrono/sys_info.h>
 #include <__chrono/system_clock.h>
 #include <__chrono/time_point.h>
 #include <__chrono/weekday.h>
@@ -171,6 +172,10 @@ _LIBCPP_HIDE_FROM_ABI _Tm __convert_to_tm(const _ChronoT& 
__value) {
   if (__value.hours().count() > 
std::numeric_limits::max())
 std::__throw_format_error("Formatting hh_mm_ss, encountered an hour 
overflow");
 __result.tm_hour = __value.hours().count();
+#  if !defined(_LIBCPP_HAS_NO_INCOMPLETE_TZDB)
+  } else if constexpr (same_as<_ChronoT, chrono::sys_info>) {
+// Has no time information.
+#  endif
   } else
 static_assert(sizeof(_ChronoT) == 0, "Add the missing type 
specialization");
 
diff --git a/libcxx/include/__chrono/formatter.h 
b/libcxx/include/__chrono/formatter.h
index 8b8592041a1fb9..6a9f5870458b32 100644
--- a/libcxx/include/__chrono/formatter.h
+++ b/libcxx/include/__chrono/formatter.h
@@ -24,6 +24,7 @@
 #include <__chrono/ostream.h>
 #include <__chrono/parser_std_format_spec.h>
 #include <__chrono/statically_widen.h>
+#include <__chrono/sys_info.h>
 #include <__chrono/system_clock.h>
 #include <__chrono/time_point.h>
 #include <__chrono/weekday.h>
@@ -185,10 +186,11 @@ __format_zone_offset(basic_stringstream<_CharT>& __sstr, 
chrono::seconds __offse
 
   chrono::hh_mm_ss __hms{__offset};
   std::ostreambuf_iterator<_CharT> __out_it{__sstr};
+  // Note HMS does not allow formatting hours > 23, but the offset is not 
limited to 24H.
+  std::format_to(__out_it, _LIBCPP_STATICALLY_WIDEN(_CharT, "{:02}"), 
__hms.hours().count());
   if (__modifier)
-std::format_to(__out_it, _LIBCPP_STATICALLY_WIDEN(_CharT, "{:%H:%M}"), 
__hms);
-  else
-std::format_to(__out_it, _LIBCPP_STATICALLY_WIDEN(_CharT, "{:%H%M}"), 
__hms);
+__sstr << _CharT(':');
+  std::format_to(__out_it, _LIBCPP_STATICALLY_WIDEN(_CharT, "{:02}"), 
__hms.minutes().count());
 }
 
 // Helper to store the time zone information needed for formatting.
@@ -202,6 +204,12 @@ struct _LIBCPP_HIDE_FROM_ABI __time_zone {
 template 
 _LIBCPP_HIDE_FROM_ABI __time_zone __convert_to_time_zone([[maybe_unused]] 
const _Tp& __value) {
   __time_zone 

[llvm-branch-commits] [libcxx] [libc++][TZDB] Adds sys_info formatter. (PR #85896)

2024-03-20 Thread Mark de Wever via llvm-branch-commits

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

>From 0dbc61d5f18f9fe5f20119805baa968f66504144 Mon Sep 17 00:00:00 2001
From: Mark de Wever 
Date: Sun, 10 Mar 2024 17:49:39 +0100
Subject: [PATCH] [libc++][TZDB] Adds sys_info formatter.

Implements parts of:
- P0355 Extending  to Calendars and Time Zones
- P1361 Integration of chrono with text formatting
---
 libcxx/docs/Status/FormatPaper.csv|   2 +-
 libcxx/include/__chrono/convert_to_tm.h   |   5 +
 libcxx/include/__chrono/formatter.h   |  44 +-
 libcxx/include/__chrono/ostream.h |  20 +++
 libcxx/include/__chrono/sys_info.h|   6 +-
 libcxx/include/chrono |   5 +
 .../time.zone.info.sys/ostream.pass.cpp   |  71 +
 .../test/libcxx/transitive_includes/cxx23.csv |   1 -
 .../test/libcxx/transitive_includes/cxx26.csv |   1 -
 .../time/time.syn/formatter.sys_info.pass.cpp | 137 ++
 .../time.zone.info.sys/ostream.pass.cpp   |  48 ++
 11 files changed, 330 insertions(+), 10 deletions(-)
 create mode 100644 
libcxx/test/libcxx/time/time.zone/time.zone.info/time.zone.info.sys/ostream.pass.cpp
 create mode 100644 libcxx/test/std/time/time.syn/formatter.sys_info.pass.cpp
 create mode 100644 
libcxx/test/std/time/time.zone/time.zone.info/time.zone.info.sys/ostream.pass.cpp

diff --git a/libcxx/docs/Status/FormatPaper.csv 
b/libcxx/docs/Status/FormatPaper.csv
index 82da54284c7386..32166ec72da753 100644
--- a/libcxx/docs/Status/FormatPaper.csv
+++ b/libcxx/docs/Status/FormatPaper.csv
@@ -24,7 +24,7 @@ Section,Description,Dependencies,Assignee,Status,First 
released version
 `[time.syn] `_,"Formatter 
``chrono::year_month_weekday``",,Mark de Wever,|Complete|,16.0
 `[time.syn] `_,"Formatter 
``chrono::year_month_weekday_last``",,Mark de Wever,|Complete|,16.0
 `[time.syn] `_,"Formatter 
``chrono::hh_mm_ss>``",,Mark de Wever,|Complete|,17.0
-`[time.syn] `_,"Formatter ``chrono::sys_info``",A 
 implementation,Mark de Wever,,
+`[time.syn] `_,"Formatter 
``chrono::sys_info``",,Mark de Wever,|Complete|,19.0
 `[time.syn] `_,"Formatter 
``chrono::local_info``",A  implementation,Mark de Wever,,
 `[time.syn] `_,"Formatter 
``chrono::zoned_time``",A  
implementation,Mark de Wever,,
 
diff --git a/libcxx/include/__chrono/convert_to_tm.h 
b/libcxx/include/__chrono/convert_to_tm.h
index 1301cd6f1f1ada..d2c5cf922ba671 100644
--- a/libcxx/include/__chrono/convert_to_tm.h
+++ b/libcxx/include/__chrono/convert_to_tm.h
@@ -20,6 +20,7 @@
 #include <__chrono/month_weekday.h>
 #include <__chrono/monthday.h>
 #include <__chrono/statically_widen.h>
+#include <__chrono/sys_info.h>
 #include <__chrono/system_clock.h>
 #include <__chrono/time_point.h>
 #include <__chrono/weekday.h>
@@ -171,6 +172,10 @@ _LIBCPP_HIDE_FROM_ABI _Tm __convert_to_tm(const _ChronoT& 
__value) {
   if (__value.hours().count() > 
std::numeric_limits::max())
 std::__throw_format_error("Formatting hh_mm_ss, encountered an hour 
overflow");
 __result.tm_hour = __value.hours().count();
+#  if !defined(_LIBCPP_HAS_NO_INCOMPLETE_TZDB)
+  } else if constexpr (same_as<_ChronoT, chrono::sys_info>) {
+// Has no time information.
+#  endif
   } else
 static_assert(sizeof(_ChronoT) == 0, "Add the missing type 
specialization");
 
diff --git a/libcxx/include/__chrono/formatter.h 
b/libcxx/include/__chrono/formatter.h
index 8b8592041a1fb9..6a9f5870458b32 100644
--- a/libcxx/include/__chrono/formatter.h
+++ b/libcxx/include/__chrono/formatter.h
@@ -24,6 +24,7 @@
 #include <__chrono/ostream.h>
 #include <__chrono/parser_std_format_spec.h>
 #include <__chrono/statically_widen.h>
+#include <__chrono/sys_info.h>
 #include <__chrono/system_clock.h>
 #include <__chrono/time_point.h>
 #include <__chrono/weekday.h>
@@ -185,10 +186,11 @@ __format_zone_offset(basic_stringstream<_CharT>& __sstr, 
chrono::seconds __offse
 
   chrono::hh_mm_ss __hms{__offset};
   std::ostreambuf_iterator<_CharT> __out_it{__sstr};
+  // Note HMS does not allow formatting hours > 23, but the offset is not 
limited to 24H.
+  std::format_to(__out_it, _LIBCPP_STATICALLY_WIDEN(_CharT, "{:02}"), 
__hms.hours().count());
   if (__modifier)
-std::format_to(__out_it, _LIBCPP_STATICALLY_WIDEN(_CharT, "{:%H:%M}"), 
__hms);
-  else
-std::format_to(__out_it, _LIBCPP_STATICALLY_WIDEN(_CharT, "{:%H%M}"), 
__hms);
+__sstr << _CharT(':');
+  std::format_to(__out_it, _LIBCPP_STATICALLY_WIDEN(_CharT, "{:02}"), 
__hms.minutes().count());
 }
 
 // Helper to store the time zone information needed for formatting.
@@ -202,6 +204,12 @@ struct _LIBCPP_HIDE_FROM_ABI __time_zone {
 template 
 _LIBCPP_HIDE_FROM_ABI __time_zone __convert_to_time_zone([[maybe_unused]] 
const _Tp& __value) {
   __time_zone 

[llvm-branch-commits] [libcxx] release/18.x: [libcxx] [modules] Fix relative paths with absolute LIBCXX_INSTALL_MODULES_DIR (#85756) (PR #85907)

2024-03-20 Thread Mark de Wever via llvm-branch-commits

https://github.com/mordante approved this pull request.


https://github.com/llvm/llvm-project/pull/85907
___
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++][TZDB] Adds sys_info formatter. (PR #85896)

2024-03-20 Thread Mark de Wever via llvm-branch-commits

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

>From 7372394c21017fe3840a6c7a6c92ff9b66f0d13d Mon Sep 17 00:00:00 2001
From: Mark de Wever 
Date: Sun, 10 Mar 2024 17:49:39 +0100
Subject: [PATCH] [libc++][TZDB] Adds sys_info formatter.

Implements parts of:
- P0355 Extending  to Calendars and Time Zones
- P1361 Integration of chrono with text formatting
---
 libcxx/docs/Status/FormatPaper.csv|   2 +-
 libcxx/include/__chrono/convert_to_tm.h   |   5 +
 libcxx/include/__chrono/formatter.h   |  37 +
 libcxx/include/__chrono/ostream.h |  20 +++
 libcxx/include/__chrono/sys_info.h|   6 +-
 libcxx/include/chrono |   5 +
 .../time.zone.info.sys/ostream.pass.cpp   |  71 +
 .../test/libcxx/transitive_includes/cxx23.csv |   1 -
 .../test/libcxx/transitive_includes/cxx26.csv |   1 -
 .../time/time.syn/formatter.sys_info.pass.cpp | 137 ++
 .../time.zone.info.sys/ostream.pass.cpp   |  48 ++
 11 files changed, 326 insertions(+), 7 deletions(-)
 create mode 100644 
libcxx/test/libcxx/time/time.zone/time.zone.info/time.zone.info.sys/ostream.pass.cpp
 create mode 100644 libcxx/test/std/time/time.syn/formatter.sys_info.pass.cpp
 create mode 100644 
libcxx/test/std/time/time.zone/time.zone.info/time.zone.info.sys/ostream.pass.cpp

diff --git a/libcxx/docs/Status/FormatPaper.csv 
b/libcxx/docs/Status/FormatPaper.csv
index 82da54284c7386..32166ec72da753 100644
--- a/libcxx/docs/Status/FormatPaper.csv
+++ b/libcxx/docs/Status/FormatPaper.csv
@@ -24,7 +24,7 @@ Section,Description,Dependencies,Assignee,Status,First 
released version
 `[time.syn] `_,"Formatter 
``chrono::year_month_weekday``",,Mark de Wever,|Complete|,16.0
 `[time.syn] `_,"Formatter 
``chrono::year_month_weekday_last``",,Mark de Wever,|Complete|,16.0
 `[time.syn] `_,"Formatter 
``chrono::hh_mm_ss>``",,Mark de Wever,|Complete|,17.0
-`[time.syn] `_,"Formatter ``chrono::sys_info``",A 
 implementation,Mark de Wever,,
+`[time.syn] `_,"Formatter 
``chrono::sys_info``",,Mark de Wever,|Complete|,19.0
 `[time.syn] `_,"Formatter 
``chrono::local_info``",A  implementation,Mark de Wever,,
 `[time.syn] `_,"Formatter 
``chrono::zoned_time``",A  
implementation,Mark de Wever,,
 
diff --git a/libcxx/include/__chrono/convert_to_tm.h 
b/libcxx/include/__chrono/convert_to_tm.h
index 1301cd6f1f1ada..d2c5cf922ba671 100644
--- a/libcxx/include/__chrono/convert_to_tm.h
+++ b/libcxx/include/__chrono/convert_to_tm.h
@@ -20,6 +20,7 @@
 #include <__chrono/month_weekday.h>
 #include <__chrono/monthday.h>
 #include <__chrono/statically_widen.h>
+#include <__chrono/sys_info.h>
 #include <__chrono/system_clock.h>
 #include <__chrono/time_point.h>
 #include <__chrono/weekday.h>
@@ -171,6 +172,10 @@ _LIBCPP_HIDE_FROM_ABI _Tm __convert_to_tm(const _ChronoT& 
__value) {
   if (__value.hours().count() > 
std::numeric_limits::max())
 std::__throw_format_error("Formatting hh_mm_ss, encountered an hour 
overflow");
 __result.tm_hour = __value.hours().count();
+#  if !defined(_LIBCPP_HAS_NO_INCOMPLETE_TZDB)
+  } else if constexpr (same_as<_ChronoT, chrono::sys_info>) {
+// Has no time information.
+#  endif
   } else
 static_assert(sizeof(_ChronoT) == 0, "Add the missing type 
specialization");
 
diff --git a/libcxx/include/__chrono/formatter.h 
b/libcxx/include/__chrono/formatter.h
index 8b8592041a1fb9..f5474e3ea6d078 100644
--- a/libcxx/include/__chrono/formatter.h
+++ b/libcxx/include/__chrono/formatter.h
@@ -24,6 +24,7 @@
 #include <__chrono/ostream.h>
 #include <__chrono/parser_std_format_spec.h>
 #include <__chrono/statically_widen.h>
+#include <__chrono/sys_info.h>
 #include <__chrono/system_clock.h>
 #include <__chrono/time_point.h>
 #include <__chrono/weekday.h>
@@ -202,6 +203,12 @@ struct _LIBCPP_HIDE_FROM_ABI __time_zone {
 template 
 _LIBCPP_HIDE_FROM_ABI __time_zone __convert_to_time_zone([[maybe_unused]] 
const _Tp& __value) {
   __time_zone __result;
+#  if !defined(_LIBCPP_HAS_NO_INCOMPLETE_TZDB)
+  if constexpr (same_as<_Tp, chrono::sys_info>) {
+__result.__offset = __value.offset;
+__result.__abbrev = __value.abbrev;
+  }
+#  endif
   return __result;
 }
 
@@ -411,6 +418,10 @@ _LIBCPP_HIDE_FROM_ABI constexpr bool __weekday_ok(const 
_Tp& __value) {
 return __value.weekday().ok();
   else if constexpr (__is_hh_mm_ss<_Tp>)
 return true;
+#  if !defined(_LIBCPP_HAS_NO_INCOMPLETE_TZDB)
+  else if constexpr (same_as<_Tp, chrono::sys_info>)
+return true;
+#  endif
   else
 static_assert(sizeof(_Tp) == 0, "Add the missing type specialization");
 }
@@ -451,6 +462,10 @@ _LIBCPP_HIDE_FROM_ABI constexpr bool 
__weekday_name_ok(const _Tp& __value) {
 return __value.weekday().ok();
   else if 

[llvm-branch-commits] [libcxx] [libc++][TZDB] Adds sys_info formatter. (PR #85896)

2024-03-20 Thread Mark de Wever via llvm-branch-commits

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

Implements parts of:
- P0355 Extending  to Calendars and Time Zones
- P1361 Integration of chrono with text formatting

>From 5597a07ac32a21d05b674d767395ee7583d11073 Mon Sep 17 00:00:00 2001
From: Mark de Wever 
Date: Sun, 10 Mar 2024 17:49:39 +0100
Subject: [PATCH] [libc++][TZDB] Adds sys_info formatter.

Implements parts of:
- P0355 Extending  to Calendars and Time Zones
- P1361 Integration of chrono with text formatting
---
 libcxx/docs/Status/FormatPaper.csv|   2 +-
 libcxx/include/__chrono/convert_to_tm.h   |   5 +
 libcxx/include/__chrono/formatter.h   |  37 +
 libcxx/include/__chrono/ostream.h |  20 +++
 libcxx/include/chrono |   5 +
 .../time.zone.info.sys/ostream.pass.cpp   |  71 +
 .../time/time.syn/formatter.sys_info.pass.cpp | 138 ++
 .../time.zone.info.sys/ostream.pass.cpp   |  48 ++
 8 files changed, 325 insertions(+), 1 deletion(-)
 create mode 100644 
libcxx/test/libcxx/time/time.zone/time.zone.info/time.zone.info.sys/ostream.pass.cpp
 create mode 100644 libcxx/test/std/time/time.syn/formatter.sys_info.pass.cpp
 create mode 100644 
libcxx/test/std/time/time.zone/time.zone.info/time.zone.info.sys/ostream.pass.cpp

diff --git a/libcxx/docs/Status/FormatPaper.csv 
b/libcxx/docs/Status/FormatPaper.csv
index 82da54284c7386..32166ec72da753 100644
--- a/libcxx/docs/Status/FormatPaper.csv
+++ b/libcxx/docs/Status/FormatPaper.csv
@@ -24,7 +24,7 @@ Section,Description,Dependencies,Assignee,Status,First 
released version
 `[time.syn] `_,"Formatter 
``chrono::year_month_weekday``",,Mark de Wever,|Complete|,16.0
 `[time.syn] `_,"Formatter 
``chrono::year_month_weekday_last``",,Mark de Wever,|Complete|,16.0
 `[time.syn] `_,"Formatter 
``chrono::hh_mm_ss>``",,Mark de Wever,|Complete|,17.0
-`[time.syn] `_,"Formatter ``chrono::sys_info``",A 
 implementation,Mark de Wever,,
+`[time.syn] `_,"Formatter 
``chrono::sys_info``",,Mark de Wever,|Complete|,19.0
 `[time.syn] `_,"Formatter 
``chrono::local_info``",A  implementation,Mark de Wever,,
 `[time.syn] `_,"Formatter 
``chrono::zoned_time``",A  
implementation,Mark de Wever,,
 
diff --git a/libcxx/include/__chrono/convert_to_tm.h 
b/libcxx/include/__chrono/convert_to_tm.h
index 1301cd6f1f1ada..d2c5cf922ba671 100644
--- a/libcxx/include/__chrono/convert_to_tm.h
+++ b/libcxx/include/__chrono/convert_to_tm.h
@@ -20,6 +20,7 @@
 #include <__chrono/month_weekday.h>
 #include <__chrono/monthday.h>
 #include <__chrono/statically_widen.h>
+#include <__chrono/sys_info.h>
 #include <__chrono/system_clock.h>
 #include <__chrono/time_point.h>
 #include <__chrono/weekday.h>
@@ -171,6 +172,10 @@ _LIBCPP_HIDE_FROM_ABI _Tm __convert_to_tm(const _ChronoT& 
__value) {
   if (__value.hours().count() > 
std::numeric_limits::max())
 std::__throw_format_error("Formatting hh_mm_ss, encountered an hour 
overflow");
 __result.tm_hour = __value.hours().count();
+#  if !defined(_LIBCPP_HAS_NO_INCOMPLETE_TZDB)
+  } else if constexpr (same_as<_ChronoT, chrono::sys_info>) {
+// Has no time information.
+#  endif
   } else
 static_assert(sizeof(_ChronoT) == 0, "Add the missing type 
specialization");
 
diff --git a/libcxx/include/__chrono/formatter.h 
b/libcxx/include/__chrono/formatter.h
index 8b8592041a1fb9..f5474e3ea6d078 100644
--- a/libcxx/include/__chrono/formatter.h
+++ b/libcxx/include/__chrono/formatter.h
@@ -24,6 +24,7 @@
 #include <__chrono/ostream.h>
 #include <__chrono/parser_std_format_spec.h>
 #include <__chrono/statically_widen.h>
+#include <__chrono/sys_info.h>
 #include <__chrono/system_clock.h>
 #include <__chrono/time_point.h>
 #include <__chrono/weekday.h>
@@ -202,6 +203,12 @@ struct _LIBCPP_HIDE_FROM_ABI __time_zone {
 template 
 _LIBCPP_HIDE_FROM_ABI __time_zone __convert_to_time_zone([[maybe_unused]] 
const _Tp& __value) {
   __time_zone __result;
+#  if !defined(_LIBCPP_HAS_NO_INCOMPLETE_TZDB)
+  if constexpr (same_as<_Tp, chrono::sys_info>) {
+__result.__offset = __value.offset;
+__result.__abbrev = __value.abbrev;
+  }
+#  endif
   return __result;
 }
 
@@ -411,6 +418,10 @@ _LIBCPP_HIDE_FROM_ABI constexpr bool __weekday_ok(const 
_Tp& __value) {
 return __value.weekday().ok();
   else if constexpr (__is_hh_mm_ss<_Tp>)
 return true;
+#  if !defined(_LIBCPP_HAS_NO_INCOMPLETE_TZDB)
+  else if constexpr (same_as<_Tp, chrono::sys_info>)
+return true;
+#  endif
   else
 static_assert(sizeof(_Tp) == 0, "Add the missing type specialization");
 }
@@ -451,6 +462,10 @@ _LIBCPP_HIDE_FROM_ABI constexpr bool 
__weekday_name_ok(const _Tp& __value) {
 return __value.weekday().ok();
   else if constexpr (__is_hh_mm_ss<_Tp>)
 return true;

[llvm-branch-commits] [clang] release/18.x: Reland Print library module manifest path again (#84881) (PR #85637)

2024-03-19 Thread Mark de Wever via llvm-branch-commits

mordante wrote:

Based on the [post review comments 
](https://github.com/llvm/llvm-project/pull/84881#issuecomment-2003793001) on 
the original PR I feel I need to do additional work. The feature originally 
landed shortly before branching. Based on the number of issues we had with I 
feel we should not backport it.

https://github.com/llvm/llvm-project/pull/85637
___
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++][TZDB] Improves time zone format specifiers. (PR #85797)

2024-03-19 Thread Mark de Wever via llvm-branch-commits

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

Per [tab:time.format.spec]
%z  The offset from UTC as specified in ISO 8601-1:2019, subclause
5.3.4.1. For example -0430 refers to 4 hours 30 minutes behind UTC.
If the offset is zero, + is used. The modified commands %Ez and
%Oz insert a : between the hours and minutes: -04:30. If the offset
information is not available, an exception of type format_error is
thrown.

Typically the modified versions Oz or Ez would have wording like

  The modified command %OS produces the locale's alternative
  representation.

In this case the modified version does not depend on the locale.

This change is a preparation for formatting sys_info which has time zone 
information. The function time_put<_CharT>::put() does not have proper time 
zone support, therefore it's a manual implementation.

Fixes https://github.com/llvm/llvm-project/issues/78184

>From 6327aeec1a6adfb1be3dcb95aa1f0ad6204213f4 Mon Sep 17 00:00:00 2001
From: Mark de Wever 
Date: Sun, 10 Mar 2024 17:49:39 +0100
Subject: [PATCH] [libc++][TZDB] Improves time zone format specifiers.

Per [tab:time.format.spec]
%z  The offset from UTC as specified in ISO 8601-1:2019, subclause
5.3.4.1. For example -0430 refers to 4 hours 30 minutes behind UTC.
If the offset is zero, + is used. The modified commands %Ez and
%Oz insert a : between the hours and minutes: -04:30. If the offset
information is not available, an exception of type format_error is
thrown.

Typically the modified versions Oz or Ez would have wording like

  The modified command %OS produces the locale's alternative
  representation.

In this case the modified version does not depend on the locale.

This change is a preparation for formatting sys_info which has time zone
information. The function time_put<_CharT>::put() does not have proper
time zone support, therefore it's a manual implementation.

Fixes https://github.com/llvm/llvm-project/issues/78184
---
 libcxx/include/__chrono/formatter.h   | 50 ++-
 .../time.syn/formatter.file_time.pass.cpp | 39 ++-
 .../time/time.syn/formatter.sys_time.pass.cpp | 39 ++-
 3 files changed, 56 insertions(+), 72 deletions(-)

diff --git a/libcxx/include/__chrono/formatter.h 
b/libcxx/include/__chrono/formatter.h
index b64cae529a294d..8b8592041a1fb9 100644
--- a/libcxx/include/__chrono/formatter.h
+++ b/libcxx/include/__chrono/formatter.h
@@ -10,6 +10,7 @@
 #ifndef _LIBCPP___CHRONO_FORMATTER_H
 #define _LIBCPP___CHRONO_FORMATTER_H
 
+#include <__algorithm/ranges_copy.h>
 #include <__chrono/calendar.h>
 #include <__chrono/concepts.h>
 #include <__chrono/convert_to_tm.h>
@@ -170,10 +171,45 @@ _LIBCPP_HIDE_FROM_ABI void 
__format_century(basic_stringstream<_CharT>& __sstr,
   __sstr << std::format(_LIBCPP_STATICALLY_WIDEN(_CharT, "{:02}"), __century);
 }
 
+// Implements the %z format specifier according to [tab:time.format.spec], 
where
+// '__modifier' signals %Oz or %Ez were used. (Both modifiers behave the same,
+// so there is no need to distinguish between them.)
+template 
+_LIBCPP_HIDE_FROM_ABI void
+__format_zone_offset(basic_stringstream<_CharT>& __sstr, chrono::seconds 
__offset, bool __modifier) {
+  if (__offset < 0s) {
+__sstr << _CharT('-');
+__offset = -__offset;
+  } else
+__sstr << _CharT('+');
+
+  chrono::hh_mm_ss __hms{__offset};
+  std::ostreambuf_iterator<_CharT> __out_it{__sstr};
+  if (__modifier)
+std::format_to(__out_it, _LIBCPP_STATICALLY_WIDEN(_CharT, "{:%H:%M}"), 
__hms);
+  else
+std::format_to(__out_it, _LIBCPP_STATICALLY_WIDEN(_CharT, "{:%H%M}"), 
__hms);
+}
+
+// Helper to store the time zone information needed for formatting.
+struct _LIBCPP_HIDE_FROM_ABI __time_zone {
+  // Typically these abbreviations as short and fit in the string's internal
+  // buffer.
+  string __abbrev{"UTC"};
+  chrono::seconds __offset{0};
+};
+
+template 
+_LIBCPP_HIDE_FROM_ABI __time_zone __convert_to_time_zone([[maybe_unused]] 
const _Tp& __value) {
+  __time_zone __result;
+  return __result;
+}
+
 template 
 _LIBCPP_HIDE_FROM_ABI void __format_chrono_using_chrono_specs(
 basic_stringstream<_CharT>& __sstr, const _Tp& __value, 
basic_string_view<_CharT> __chrono_specs) {
   tm __t  = std::__convert_to_tm(__value);
+  __time_zone __z = __formatter::__convert_to_time_zone(__value);
   const auto& __facet = std::use_facet>(__sstr.getloc());
   for (auto __it = __chrono_specs.begin(); __it != __chrono_specs.end(); 
++__it) {
 if (*__it == _CharT('%')) {
@@ -296,9 +332,13 @@ _LIBCPP_HIDE_FROM_ABI void 
__format_chrono_using_chrono_specs(
   {__sstr}, __sstr, _CharT(' '), std::addressof(__t), 
std::to_address(__s), std::to_address(__it + 1));
   } break;
 
+  case _CharT('z'):
+__formatter::__format_zone_offset(__sstr, __z.__offset, false);
+break;
+
   case _CharT('Z'):
-// TODO FMT 

[llvm-branch-commits] [libcxx] [NFC][libc++][TZDB] Refactors argument order. (PR #85781)

2024-03-19 Thread Mark de Wever via llvm-branch-commits

https://github.com/mordante edited 
https://github.com/llvm/llvm-project/pull/85781
___
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] [NFC] Refactors argument order. (PR #85781)

2024-03-19 Thread Mark de Wever via llvm-branch-commits

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

Putting the output reference argument first looks more sensible.

>From 1af98d79952669b1ce05b42aeeae32bd4ea83ee7 Mon Sep 17 00:00:00 2001
From: Mark de Wever 
Date: Sun, 10 Mar 2024 17:49:39 +0100
Subject: [PATCH] [NFC] Refactors argument order.

Putting the output reference argument first looks more sensible.
---
 libcxx/include/__chrono/formatter.h | 28 ++--
 1 file changed, 14 insertions(+), 14 deletions(-)

diff --git a/libcxx/include/__chrono/formatter.h 
b/libcxx/include/__chrono/formatter.h
index 4ad59382a4148a..b64cae529a294d 100644
--- a/libcxx/include/__chrono/formatter.h
+++ b/libcxx/include/__chrono/formatter.h
@@ -79,7 +79,7 @@ namespace __formatter {
 // small). Therefore a duration uses its own conversion.
 template 
 _LIBCPP_HIDE_FROM_ABI void
-__format_sub_seconds(const chrono::duration<_Rep, _Period>& __value, 
basic_stringstream<_CharT>& __sstr) {
+__format_sub_seconds(basic_stringstream<_CharT>& __sstr, const 
chrono::duration<_Rep, _Period>& __value) {
   __sstr << std::use_facet>(__sstr.getloc()).decimal_point();
 
   using __duration = chrono::duration<_Rep, _Period>;
@@ -110,13 +110,13 @@ __format_sub_seconds(const chrono::duration<_Rep, 
_Period>& __value, basic_strin
 }
 
 template 
-_LIBCPP_HIDE_FROM_ABI void __format_sub_seconds(const _Tp& __value, 
basic_stringstream<_CharT>& __sstr) {
-  __formatter::__format_sub_seconds(__value.time_since_epoch(), __sstr);
+_LIBCPP_HIDE_FROM_ABI void __format_sub_seconds(basic_stringstream<_CharT>& 
__sstr, const _Tp& __value) {
+  __formatter::__format_sub_seconds(__sstr, __value.time_since_epoch());
 }
 
 template 
 _LIBCPP_HIDE_FROM_ABI void
-__format_sub_seconds(const chrono::hh_mm_ss<_Duration>& __value, 
basic_stringstream<_CharT>& __sstr) {
+__format_sub_seconds(basic_stringstream<_CharT>& __sstr, const 
chrono::hh_mm_ss<_Duration>& __value) {
   __sstr << std::use_facet>(__sstr.getloc()).decimal_point();
   if constexpr (chrono::treat_as_floating_point_v)
 std::format_to(std::ostreambuf_iterator<_CharT>{__sstr},
@@ -143,7 +143,7 @@ consteval bool __use_fraction() {
 }
 
 template 
-_LIBCPP_HIDE_FROM_ABI void __format_year(int __year, 
basic_stringstream<_CharT>& __sstr) {
+_LIBCPP_HIDE_FROM_ABI void __format_year(basic_stringstream<_CharT>& __sstr, 
int __year) {
   if (__year < 0) {
 __sstr << _CharT('-');
 __year = -__year;
@@ -159,7 +159,7 @@ _LIBCPP_HIDE_FROM_ABI void __format_year(int __year, 
basic_stringstream<_CharT>&
 }
 
 template 
-_LIBCPP_HIDE_FROM_ABI void __format_century(int __year, 
basic_stringstream<_CharT>& __sstr) {
+_LIBCPP_HIDE_FROM_ABI void __format_century(basic_stringstream<_CharT>& 
__sstr, int __year) {
   // TODO FMT Write an issue
   // [tab:time.format.spec]
   //   %C The year divided by 100 using floored division. If the result is a
@@ -172,7 +172,7 @@ _LIBCPP_HIDE_FROM_ABI void __format_century(int __year, 
basic_stringstream<_Char
 
 template 
 _LIBCPP_HIDE_FROM_ABI void __format_chrono_using_chrono_specs(
-const _Tp& __value, basic_stringstream<_CharT>& __sstr, 
basic_string_view<_CharT> __chrono_specs) {
+basic_stringstream<_CharT>& __sstr, const _Tp& __value, 
basic_string_view<_CharT> __chrono_specs) {
   tm __t  = std::__convert_to_tm(__value);
   const auto& __facet = std::use_facet>(__sstr.getloc());
   for (auto __it = __chrono_specs.begin(); __it != __chrono_specs.end(); 
++__it) {
@@ -196,7 +196,7 @@ _LIBCPP_HIDE_FROM_ABI void 
__format_chrono_using_chrono_specs(
 // strftime's output is only defined in the range [00, 99].
 int __year = __t.tm_year + 1900;
 if (__year < 1000 || __year > )
-  __formatter::__format_century(__year, __sstr);
+  __formatter::__format_century(__sstr, __year);
 else
   __facet.put(
   {__sstr}, __sstr, _CharT(' '), std::addressof(__t), 
std::to_address(__s), std::to_address(__it + 1));
@@ -242,7 +242,7 @@ _LIBCPP_HIDE_FROM_ABI void 
__format_chrono_using_chrono_specs(
 __facet.put(
 {__sstr}, __sstr, _CharT(' '), std::addressof(__t), 
std::to_address(__s), std::to_address(__it + 1));
 if constexpr (__use_fraction<_Tp>())
-  __formatter::__format_sub_seconds(__value, __sstr);
+  __formatter::__format_sub_seconds(__sstr, __value);
 break;
 
 // Unlike time_put and strftime the formatting library requires %Y
@@ -283,13 +283,13 @@ _LIBCPP_HIDE_FROM_ABI void 
__format_chrono_using_chrono_specs(
 // Depending on the platform's libc the range of supported years is
 // limited. Intead of of testing all conditions use the internal
 // implementation unconditionally.
-__formatter::__format_year(__t.tm_year + 1900, __sstr);
+__formatter::__format_year(__sstr, __t.tm_year + 1900);
 break;
 
   case _CharT('F'): {
 int __year = __t.tm_year + 1900;
 

[llvm-branch-commits] [libcxx] [libc++][chrono] Adds the sys_info class. (PR #85619)

2024-03-18 Thread Mark de Wever via llvm-branch-commits


@@ -41,4 +41,5 @@
 "`4001 `__","``iota_view`` should provide 
``empty``","Kona November 2023","","","|ranges|"
 "","","","","",""
 "`3343 `__","Ordering of calls to ``unlock()`` and 
``notify_all()`` in Effects element of ``notify_all_at_thread_exit()`` should 
be reversed","Not Yet Adopted","|Complete|","16.0",""
+"","","The sys_info range should be affected by save","Not Yet 
Adopted","|Complete|","19.0"

mordante wrote:

This has been discussed with Howard and I'll file an LWG issue.

https://github.com/llvm/llvm-project/pull/85619
___
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] Completes the tzdb class. (PR #82157)

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

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

>From 7a742c0e564ffa37ad299cf6186faadd61e34d29 Mon Sep 17 00:00:00 2001
From: Mark de Wever 
Date: Fri, 23 Sep 2022 18:33:20 +0200
Subject: [PATCH] [libc++][chrono] Completes the tzdb class.

It adds the missing member functions of the tzdb class and adds the free
functions that use these member functions.

Implements parts of:
- P0355 Extending  to Calendars and Time Zones
---
 libcxx/include/__chrono/tzdb.h| 35 
 libcxx/include/__chrono/tzdb_list.h   | 10 +++
 libcxx/include/chrono |  5 ++
 libcxx/modules/std/chrono.inc |  4 +-
 libcxx/src/tzdb.cpp   | 59 ++
 ...rono.nodiscard_extensions.compile.pass.cpp |  8 ++
 .../chrono.nodiscard_extensions.verify.cpp|  8 ++
 .../time.zone.db.access/current_zone.pass.cpp | 77 ++
 .../time.zone.db.access/locate_zone.pass.cpp  | 62 +++
 .../time.zone.db.tzdb/current_zone.pass.cpp   | 79 +++
 .../time.zone.db.tzdb/locate_zone.pass.cpp| 64 +++
 11 files changed, 409 insertions(+), 2 deletions(-)
 create mode 100644 
libcxx/test/std/time/time.zone/time.zone.db/time.zone.db.access/current_zone.pass.cpp
 create mode 100644 
libcxx/test/std/time/time.zone/time.zone.db/time.zone.db.access/locate_zone.pass.cpp
 create mode 100644 
libcxx/test/std/time/time.zone/time.zone.db/time.zone.db.tzdb/current_zone.pass.cpp
 create mode 100644 
libcxx/test/std/time/time.zone/time.zone.db/time.zone.db.tzdb/locate_zone.pass.cpp

diff --git a/libcxx/include/__chrono/tzdb.h b/libcxx/include/__chrono/tzdb.h
index 45c20f279f9c96..667d2406645658 100644
--- a/libcxx/include/__chrono/tzdb.h
+++ b/libcxx/include/__chrono/tzdb.h
@@ -16,6 +16,7 @@
 // Enable the contents of the header only when libc++ was built with 
experimental features enabled.
 #if !defined(_LIBCPP_HAS_NO_INCOMPLETE_TZDB)
 
+#  include <__algorithm/ranges_lower_bound.h>
 #  include <__chrono/leap_second.h>
 #  include <__chrono/time_zone.h>
 #  include <__chrono/time_zone_link.h>
@@ -43,6 +44,40 @@ struct tzdb {
   vector links;
 
   vector leap_seconds;
+
+  [[nodiscard]] _LIBCPP_HIDE_FROM_ABI const time_zone* 
__locate_zone(string_view __name) const {
+if (const time_zone* __result = __find_in_zone(__name); __result)
+  return __result;
+
+if (auto __it = ranges::lower_bound(links, __name, {}, 
_zone_link::name);
+__it != links.end() && __it->name() == __name)
+  if (const time_zone* __result = __find_in_zone(__it->target()); __result)
+return __result;
+
+return nullptr;
+  }
+
+  _LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI const time_zone* 
locate_zone(string_view __name) const {
+if (const time_zone* __result = __locate_zone(__name))
+  return __result;
+
+std::__throw_runtime_error("tzdb: requested time zone not found");
+  }
+
+  _LIBCPP_NODISCARD_EXT _LIBCPP_AVAILABILITY_TZDB _LIBCPP_HIDE_FROM_ABI const 
time_zone* current_zone() const {
+return __current_zone();
+  }
+
+private:
+  _LIBCPP_HIDE_FROM_ABI const time_zone* __find_in_zone(string_view __name) 
const noexcept {
+if (auto __it = ranges::lower_bound(zones, __name, {}, _zone::name);
+__it != zones.end() && __it->name() == __name)
+  return std::addressof(*__it);
+
+return nullptr;
+  }
+
+  [[nodiscard]] _LIBCPP_AVAILABILITY_TZDB _LIBCPP_EXPORTED_FROM_ABI const 
time_zone* __current_zone() const;
 };
 
 } // namespace chrono
diff --git a/libcxx/include/__chrono/tzdb_list.h 
b/libcxx/include/__chrono/tzdb_list.h
index 112e04ff2ee6ac..d812312287f16e 100644
--- a/libcxx/include/__chrono/tzdb_list.h
+++ b/libcxx/include/__chrono/tzdb_list.h
@@ -17,6 +17,7 @@
 #if !defined(_LIBCPP_HAS_NO_INCOMPLETE_TZDB)
 
 #  include <__availability>
+#  include <__chrono/time_zone.h>
 #  include <__chrono/tzdb.h>
 #  include <__config>
 #  include <__fwd/string.h>
@@ -74,6 +75,15 @@ _LIBCPP_NODISCARD_EXT _LIBCPP_AVAILABILITY_TZDB 
_LIBCPP_HIDE_FROM_ABI inline con
   return get_tzdb_list().front();
 }
 
+_LIBCPP_NODISCARD_EXT _LIBCPP_AVAILABILITY_TZDB _LIBCPP_HIDE_FROM_ABI inline 
const time_zone*
+locate_zone(string_view __name) {
+  return get_tzdb().locate_zone(__name);
+}
+
+_LIBCPP_NODISCARD_EXT _LIBCPP_AVAILABILITY_TZDB _LIBCPP_HIDE_FROM_ABI inline 
const time_zone* current_zone() {
+  return get_tzdb().current_zone();
+}
+
 _LIBCPP_AVAILABILITY_TZDB _LIBCPP_EXPORTED_FROM_ABI const tzdb& reload_tzdb();
 
 _LIBCPP_NODISCARD_EXT _LIBCPP_AVAILABILITY_TZDB _LIBCPP_EXPORTED_FROM_ABI 
string remote_version();
diff --git a/libcxx/include/chrono b/libcxx/include/chrono
index 4dd43137b71820..8fdc30a3624dfc 100644
--- a/libcxx/include/chrono
+++ b/libcxx/include/chrono
@@ -689,6 +689,9 @@ struct tzdb {
   vector  zones;
   vector links;
   vectorleap_seconds;
+
+  const time_zone* locate_zone(string_view tz_name) const;
+  const time_zone* 

[llvm-branch-commits] [libcxx] [libc++] Use clang-tidy version that matches the compiler we use in the CI (PR #85305)

2024-03-15 Thread Mark de Wever via llvm-branch-commits

https://github.com/mordante approved this pull request.

@tstellar due to the new LLVM version number scheme this code would mix LLVM 17 
and LLVM 18. (LLVM 18.1 is not considered to be LLVM 18.) Since these are 
expected not to be ABI stable it seems we ran into ODR violations. For main I 
landed a different fix that has other improvements. These improvements should 
not be backported to LLVM-18. This is the minimal fix needed for LLVM-18.

LGTM!

https://github.com/llvm/llvm-project/pull/85305
___
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++] Cherry-pick the disabling of modules tests onto release/18.x (PR #85247)

2024-03-14 Thread Mark de Wever via llvm-branch-commits

mordante wrote:

> Is the fix only to switch to 18.1 in the cmake? I can do that if that's it, I 
> just don't fully understand the situation w/ clang tidy ODR violations since 
> you were the one to make these changes

That should be all. I'm also happy to do it, but that will be tomorrow.

https://github.com/llvm/llvm-project/pull/85247
___
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++] Cherry-pick the disabling of modules tests onto release/18.x (PR #85247)

2024-03-14 Thread Mark de Wever via llvm-branch-commits

mordante wrote:

> @mordante So should I close this PR?

I see you already did. Do you want to make a fix for the release branch or do 
you want me to pick that up?

https://github.com/llvm/llvm-project/pull/85247
___
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++] Cherry-pick the disabling of modules tests onto release/18.x (PR #85247)

2024-03-14 Thread Mark de Wever via llvm-branch-commits

mordante wrote:

I'd rather fix the clang-tidy integration. I'm quite sure we have ODR 
violations since we use clang-tidy 18 with clang 17 libraries. These violations 
break the modules, but other clang-tidy checks may also have issues. Changing 
https://github.com/llvm/llvm-project/blob/release/18.x/libcxx/test/tools/clang_tidy_checks/CMakeLists.txt#L8
 to 18.1 likely fixes the issue.

I forgot about the release branch when I fixed this in main.

https://github.com/llvm/llvm-project/pull/85247
___
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] release/18.x: [libc++][modules] Fixes naming inconsistency. (#83036) (PR #83156)

2024-03-08 Thread Mark de Wever via llvm-branch-commits

mordante wrote:

I assume it will then be in 18.1.1 in a few weeks.

https://github.com/llvm/llvm-project/pull/83156
___
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] Completes the tzdb class. (PR #82157)

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

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

It adds the missing member functions of the tzdb class and adds the free 
functions that use these member functions.

Implements parts of:
- P0355 Extending  to Calendars and Time Zones

>From fa05466984bcd3a73a81994e352892fd609effbf Mon Sep 17 00:00:00 2001
From: Mark de Wever 
Date: Fri, 23 Sep 2022 18:33:20 +0200
Subject: [PATCH] [libc++][chrono] Completes the tzdb class.

It adds the missing member functions of the tzdb class and adds the free
functions that use these member functions.

Implements parts of:
- P0355 Extending  to Calendars and Time Zones
---
 libcxx/include/__chrono/tzdb.h| 35 
 libcxx/include/__chrono/tzdb_list.h   | 10 +++
 libcxx/include/chrono |  5 ++
 libcxx/modules/std/chrono.inc |  4 +-
 libcxx/src/tzdb.cpp   | 59 ++
 ...rono.nodiscard_extensions.compile.pass.cpp |  8 ++
 .../chrono.nodiscard_extensions.verify.cpp|  8 ++
 .../time.zone.db.access/current_zone.pass.cpp | 77 ++
 .../time.zone.db.access/locate_zone.pass.cpp  | 62 +++
 .../time.zone.db.tzdb/current_zone.pass.cpp   | 79 +++
 .../time.zone.db.tzdb/locate_zone.pass.cpp| 64 +++
 11 files changed, 409 insertions(+), 2 deletions(-)
 create mode 100644 
libcxx/test/std/time/time.zone/time.zone.db/time.zone.db.access/current_zone.pass.cpp
 create mode 100644 
libcxx/test/std/time/time.zone/time.zone.db/time.zone.db.access/locate_zone.pass.cpp
 create mode 100644 
libcxx/test/std/time/time.zone/time.zone.db/time.zone.db.tzdb/current_zone.pass.cpp
 create mode 100644 
libcxx/test/std/time/time.zone/time.zone.db/time.zone.db.tzdb/locate_zone.pass.cpp

diff --git a/libcxx/include/__chrono/tzdb.h b/libcxx/include/__chrono/tzdb.h
index 45c20f279f9c96..667d2406645658 100644
--- a/libcxx/include/__chrono/tzdb.h
+++ b/libcxx/include/__chrono/tzdb.h
@@ -16,6 +16,7 @@
 // Enable the contents of the header only when libc++ was built with 
experimental features enabled.
 #if !defined(_LIBCPP_HAS_NO_INCOMPLETE_TZDB)
 
+#  include <__algorithm/ranges_lower_bound.h>
 #  include <__chrono/leap_second.h>
 #  include <__chrono/time_zone.h>
 #  include <__chrono/time_zone_link.h>
@@ -43,6 +44,40 @@ struct tzdb {
   vector links;
 
   vector leap_seconds;
+
+  [[nodiscard]] _LIBCPP_HIDE_FROM_ABI const time_zone* 
__locate_zone(string_view __name) const {
+if (const time_zone* __result = __find_in_zone(__name); __result)
+  return __result;
+
+if (auto __it = ranges::lower_bound(links, __name, {}, 
_zone_link::name);
+__it != links.end() && __it->name() == __name)
+  if (const time_zone* __result = __find_in_zone(__it->target()); __result)
+return __result;
+
+return nullptr;
+  }
+
+  _LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI const time_zone* 
locate_zone(string_view __name) const {
+if (const time_zone* __result = __locate_zone(__name))
+  return __result;
+
+std::__throw_runtime_error("tzdb: requested time zone not found");
+  }
+
+  _LIBCPP_NODISCARD_EXT _LIBCPP_AVAILABILITY_TZDB _LIBCPP_HIDE_FROM_ABI const 
time_zone* current_zone() const {
+return __current_zone();
+  }
+
+private:
+  _LIBCPP_HIDE_FROM_ABI const time_zone* __find_in_zone(string_view __name) 
const noexcept {
+if (auto __it = ranges::lower_bound(zones, __name, {}, _zone::name);
+__it != zones.end() && __it->name() == __name)
+  return std::addressof(*__it);
+
+return nullptr;
+  }
+
+  [[nodiscard]] _LIBCPP_AVAILABILITY_TZDB _LIBCPP_EXPORTED_FROM_ABI const 
time_zone* __current_zone() const;
 };
 
 } // namespace chrono
diff --git a/libcxx/include/__chrono/tzdb_list.h 
b/libcxx/include/__chrono/tzdb_list.h
index 112e04ff2ee6ac..d812312287f16e 100644
--- a/libcxx/include/__chrono/tzdb_list.h
+++ b/libcxx/include/__chrono/tzdb_list.h
@@ -17,6 +17,7 @@
 #if !defined(_LIBCPP_HAS_NO_INCOMPLETE_TZDB)
 
 #  include <__availability>
+#  include <__chrono/time_zone.h>
 #  include <__chrono/tzdb.h>
 #  include <__config>
 #  include <__fwd/string.h>
@@ -74,6 +75,15 @@ _LIBCPP_NODISCARD_EXT _LIBCPP_AVAILABILITY_TZDB 
_LIBCPP_HIDE_FROM_ABI inline con
   return get_tzdb_list().front();
 }
 
+_LIBCPP_NODISCARD_EXT _LIBCPP_AVAILABILITY_TZDB _LIBCPP_HIDE_FROM_ABI inline 
const time_zone*
+locate_zone(string_view __name) {
+  return get_tzdb().locate_zone(__name);
+}
+
+_LIBCPP_NODISCARD_EXT _LIBCPP_AVAILABILITY_TZDB _LIBCPP_HIDE_FROM_ABI inline 
const time_zone* current_zone() {
+  return get_tzdb().current_zone();
+}
+
 _LIBCPP_AVAILABILITY_TZDB _LIBCPP_EXPORTED_FROM_ABI const tzdb& reload_tzdb();
 
 _LIBCPP_NODISCARD_EXT _LIBCPP_AVAILABILITY_TZDB _LIBCPP_EXPORTED_FROM_ABI 
string remote_version();
diff --git a/libcxx/include/chrono b/libcxx/include/chrono
index 01ba15d97f3d20..e115e7a3831339 100644
--- a/libcxx/include/chrono
+++ b/libcxx/include/chrono
@@ 

[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-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] release/18.x: [libc++] Only include from the C library if it exists (#81887) (PR #82045)

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

https://github.com/mordante approved this pull request.

It looks like the Buildkite failures are due to the known Windows bot issues.

https://github.com/llvm/llvm-project/pull/82045
___
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] release/18.x: [libc++][modules] Fix disabling Unicode (#81294) (PR #81361)

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

https://github.com/mordante approved this pull request.


https://github.com/llvm/llvm-project/pull/81361
___
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] PR for llvm/llvm-project#79155 (PR #80484)

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

https://github.com/mordante approved this pull request.


https://github.com/llvm/llvm-project/pull/80484
___
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++][modules] Adds module testing. (PR #76246)

2024-01-16 Thread Mark de Wever via llvm-branch-commits

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

>From eebe9b2fab5c5eef4776852270bf70af4626cfcb Mon Sep 17 00:00:00 2001
From: Mark de Wever 
Date: Wed, 20 Dec 2023 20:43:38 +0100
Subject: [PATCH 1/3] [libc++][modules] Adds module testing.

This adds a new module test infrastructure. This requires tagging tests
using modules. The test runner uses this information to determine the
compiler flags needed to build and use the module.

Currently modules are build per test, which allows testing them for
tests with ADDITIONAL_COMPILE_FLAGS. At the moment only 4 tests use
modules. Therefore the performance penalty is not measurable. If in the
future more tests use modules it would be good to measure the overhead
and determine whether it's acceptable.
---
 libcxx/docs/TestingLibcxx.rst |  9 ++-
 libcxx/modules/std/memory.inc |  2 +
 libcxx/test/libcxx/module_std.gen.py  |  1 +
 libcxx/test/libcxx/module_std_compat.gen.py   |  1 +
 .../libcxx/selftest/modules/no-modules.sh.cpp | 14 
 .../modules/std-and-std.compat-module.sh.cpp  | 22 ++
 .../libcxx/selftest/modules/std-module.sh.cpp | 24 +++
 .../selftest/modules/std.compat-module.sh.cpp | 24 +++
 libcxx/test/std/modules/std.compat.pass.cpp   |  5 +-
 libcxx/test/std/modules/std.pass.cpp  |  5 +-
 libcxx/utils/libcxx/test/features.py  | 12 
 libcxx/utils/libcxx/test/format.py| 71 +++
 libcxx/utils/libcxx/test/modules.py   |  5 +-
 13 files changed, 190 insertions(+), 5 deletions(-)
 create mode 100644 libcxx/test/libcxx/selftest/modules/no-modules.sh.cpp
 create mode 100644 
libcxx/test/libcxx/selftest/modules/std-and-std.compat-module.sh.cpp
 create mode 100644 libcxx/test/libcxx/selftest/modules/std-module.sh.cpp
 create mode 100644 libcxx/test/libcxx/selftest/modules/std.compat-module.sh.cpp

diff --git a/libcxx/docs/TestingLibcxx.rst b/libcxx/docs/TestingLibcxx.rst
index e7645cb5885f14..50ee9d4ee400b4 100644
--- a/libcxx/docs/TestingLibcxx.rst
+++ b/libcxx/docs/TestingLibcxx.rst
@@ -394,7 +394,7 @@ Custom Directives
 ~
 
 Lit has many directives built in (e.g., ``DEFINE``, ``UNSUPPORTED``). In 
addition to those directives, libc++ adds two additional libc++-specific 
directives that makes
-writing tests easier. See `libc++-specific Lit Directives`_ for more 
information about the ``FILE_DEPENDENCIES`` and ``ADDITIONAL_COMPILE_FLAGS`` 
libc++-specific directives.
+writing tests easier. See `libc++-specific Lit Directives`_ for more 
information about the ``FILE_DEPENDENCIES``, ``ADDITIONAL_COMPILE_FLAGS``, and 
``MODULE_DEPENDENCIES`` libc++-specific directives.
 
 .. _libc++-specific Lit Directives:
 .. list-table:: libc++-specific Lit Directives
@@ -417,6 +417,13 @@ writing tests easier. See `libc++-specific Lit 
Directives`_ for more information
  - The additional compiler flags specified by a space-separated list to 
the ``ADDITIONAL_COMPILE_FLAGS`` libc++-specific Lit directive will be added to 
the end of the ``%{compile_flags}``
substitution for the test that contains it. This libc++-specific Lit 
directive makes it possible to add special compilation flags without having to 
resort to writing a ``.sh.cpp`` test (see
`Lit Meaning of libc++ Test Filenames`_), more powerful but perhaps 
overkill.
+   * - ``MODULE_DEPENDENCIES``
+ - ``// MODULE_DEPENDENCIES: std std.compat``
+ - This directive will build the required C++23 standard library
+   modules and add the additional compiler flags in
+   %{compile_flags}. (Libc++ offers these modules in C++20 as an
+   extension.)
+
 
 Benchmarks
 ==
diff --git a/libcxx/modules/std/memory.inc b/libcxx/modules/std/memory.inc
index fba2461732c1b9..ef89845457fbb9 100644
--- a/libcxx/modules/std/memory.inc
+++ b/libcxx/modules/std/memory.inc
@@ -156,7 +156,9 @@ export namespace std {
   using std::reinterpret_pointer_cast;
   using std::static_pointer_cast;
 
+#ifndef _LIBCPP_HAS_NO_RTTI
   using std::get_deleter;
+#endif // _LIBCPP_HAS_NO_RTTI
 
   // [util.smartptr.shared.io], shared_ptr I/O
 
diff --git a/libcxx/test/libcxx/module_std.gen.py 
b/libcxx/test/libcxx/module_std.gen.py
index 8e03d6e5b5b523..a9a05a0cd74e61 100644
--- a/libcxx/test/libcxx/module_std.gen.py
+++ b/libcxx/test/libcxx/module_std.gen.py
@@ -30,6 +30,7 @@
 "%{test-tools}/clang_tidy_checks/libcxx-tidy.plugin",
 "%{cxx}",
 "%{flags} %{compile_flags}",
+"std",
 )
 
 
diff --git a/libcxx/test/libcxx/module_std_compat.gen.py 
b/libcxx/test/libcxx/module_std_compat.gen.py
index c4792db3d71e62..2866066ccedc89 100644
--- a/libcxx/test/libcxx/module_std_compat.gen.py
+++ b/libcxx/test/libcxx/module_std_compat.gen.py
@@ -30,6 +30,7 @@
 "%{test-tools}/clang_tidy_checks/libcxx-tidy.plugin",
 "%{cxx}",
 "%{flags} %{compile_flags}",
+"std.compat",
 )
 
 
diff --git a/libcxx/test/libcxx/selftest/modules/no-modules.sh.cpp 

[llvm-branch-commits] [libcxx] [libc++][modules] Adds module testing. (PR #76246)

2024-01-16 Thread Mark de Wever via llvm-branch-commits


@@ -52,6 +52,21 @@ def _executeScriptInternal(test, litConfig, commands):
 return (out, err, exitCode, timeoutInfo, parsedCommands)
 
 
+def _validateModuleDependencies(modules):
+for m in modules:
+if m not in ("std", "std.compat"):
+raise RuntimeError(
+f"Invalid module dependency '{m}', only 'std' and 'std.compat' 
are valid"
+)
+
+
+def _getSubstitution(substitution, config):

mordante wrote:

This doesn't work, dsl depends on format. What would work is move this to 
config. I've copied the _appendToSubstitution and will clean up in a follow-up 
commit.

https://github.com/llvm/llvm-project/pull/76246
___
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++][modules] Adds module testing. (PR #76246)

2024-01-16 Thread Mark de Wever via llvm-branch-commits

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

>From eebe9b2fab5c5eef4776852270bf70af4626cfcb Mon Sep 17 00:00:00 2001
From: Mark de Wever 
Date: Wed, 20 Dec 2023 20:43:38 +0100
Subject: [PATCH 1/2] [libc++][modules] Adds module testing.

This adds a new module test infrastructure. This requires tagging tests
using modules. The test runner uses this information to determine the
compiler flags needed to build and use the module.

Currently modules are build per test, which allows testing them for
tests with ADDITIONAL_COMPILE_FLAGS. At the moment only 4 tests use
modules. Therefore the performance penalty is not measurable. If in the
future more tests use modules it would be good to measure the overhead
and determine whether it's acceptable.
---
 libcxx/docs/TestingLibcxx.rst |  9 ++-
 libcxx/modules/std/memory.inc |  2 +
 libcxx/test/libcxx/module_std.gen.py  |  1 +
 libcxx/test/libcxx/module_std_compat.gen.py   |  1 +
 .../libcxx/selftest/modules/no-modules.sh.cpp | 14 
 .../modules/std-and-std.compat-module.sh.cpp  | 22 ++
 .../libcxx/selftest/modules/std-module.sh.cpp | 24 +++
 .../selftest/modules/std.compat-module.sh.cpp | 24 +++
 libcxx/test/std/modules/std.compat.pass.cpp   |  5 +-
 libcxx/test/std/modules/std.pass.cpp  |  5 +-
 libcxx/utils/libcxx/test/features.py  | 12 
 libcxx/utils/libcxx/test/format.py| 71 +++
 libcxx/utils/libcxx/test/modules.py   |  5 +-
 13 files changed, 190 insertions(+), 5 deletions(-)
 create mode 100644 libcxx/test/libcxx/selftest/modules/no-modules.sh.cpp
 create mode 100644 
libcxx/test/libcxx/selftest/modules/std-and-std.compat-module.sh.cpp
 create mode 100644 libcxx/test/libcxx/selftest/modules/std-module.sh.cpp
 create mode 100644 libcxx/test/libcxx/selftest/modules/std.compat-module.sh.cpp

diff --git a/libcxx/docs/TestingLibcxx.rst b/libcxx/docs/TestingLibcxx.rst
index e7645cb5885f14e..50ee9d4ee400b45 100644
--- a/libcxx/docs/TestingLibcxx.rst
+++ b/libcxx/docs/TestingLibcxx.rst
@@ -394,7 +394,7 @@ Custom Directives
 ~
 
 Lit has many directives built in (e.g., ``DEFINE``, ``UNSUPPORTED``). In 
addition to those directives, libc++ adds two additional libc++-specific 
directives that makes
-writing tests easier. See `libc++-specific Lit Directives`_ for more 
information about the ``FILE_DEPENDENCIES`` and ``ADDITIONAL_COMPILE_FLAGS`` 
libc++-specific directives.
+writing tests easier. See `libc++-specific Lit Directives`_ for more 
information about the ``FILE_DEPENDENCIES``, ``ADDITIONAL_COMPILE_FLAGS``, and 
``MODULE_DEPENDENCIES`` libc++-specific directives.
 
 .. _libc++-specific Lit Directives:
 .. list-table:: libc++-specific Lit Directives
@@ -417,6 +417,13 @@ writing tests easier. See `libc++-specific Lit 
Directives`_ for more information
  - The additional compiler flags specified by a space-separated list to 
the ``ADDITIONAL_COMPILE_FLAGS`` libc++-specific Lit directive will be added to 
the end of the ``%{compile_flags}``
substitution for the test that contains it. This libc++-specific Lit 
directive makes it possible to add special compilation flags without having to 
resort to writing a ``.sh.cpp`` test (see
`Lit Meaning of libc++ Test Filenames`_), more powerful but perhaps 
overkill.
+   * - ``MODULE_DEPENDENCIES``
+ - ``// MODULE_DEPENDENCIES: std std.compat``
+ - This directive will build the required C++23 standard library
+   modules and add the additional compiler flags in
+   %{compile_flags}. (Libc++ offers these modules in C++20 as an
+   extension.)
+
 
 Benchmarks
 ==
diff --git a/libcxx/modules/std/memory.inc b/libcxx/modules/std/memory.inc
index fba2461732c1b9d..ef89845457fbb9f 100644
--- a/libcxx/modules/std/memory.inc
+++ b/libcxx/modules/std/memory.inc
@@ -156,7 +156,9 @@ export namespace std {
   using std::reinterpret_pointer_cast;
   using std::static_pointer_cast;
 
+#ifndef _LIBCPP_HAS_NO_RTTI
   using std::get_deleter;
+#endif // _LIBCPP_HAS_NO_RTTI
 
   // [util.smartptr.shared.io], shared_ptr I/O
 
diff --git a/libcxx/test/libcxx/module_std.gen.py 
b/libcxx/test/libcxx/module_std.gen.py
index 8e03d6e5b5b5235..a9a05a0cd74e614 100644
--- a/libcxx/test/libcxx/module_std.gen.py
+++ b/libcxx/test/libcxx/module_std.gen.py
@@ -30,6 +30,7 @@
 "%{test-tools}/clang_tidy_checks/libcxx-tidy.plugin",
 "%{cxx}",
 "%{flags} %{compile_flags}",
+"std",
 )
 
 
diff --git a/libcxx/test/libcxx/module_std_compat.gen.py 
b/libcxx/test/libcxx/module_std_compat.gen.py
index c4792db3d71e624..2866066ccedc89c 100644
--- a/libcxx/test/libcxx/module_std_compat.gen.py
+++ b/libcxx/test/libcxx/module_std_compat.gen.py
@@ -30,6 +30,7 @@
 "%{test-tools}/clang_tidy_checks/libcxx-tidy.plugin",
 "%{cxx}",
 "%{flags} %{compile_flags}",
+"std.compat",
 )
 
 
diff --git 

[llvm-branch-commits] [libcxx] [libc++][modules] Increase clang-tidy version used. (PR #76268)

2024-01-12 Thread Mark de Wever via llvm-branch-commits

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

>From b3c567f4a4369b1d22f189f272a3fa86c1f0f401 Mon Sep 17 00:00:00 2001
From: Mark de Wever 
Date: Fri, 22 Dec 2023 21:43:57 +0100
Subject: [PATCH] [libc++][modules] Increase clang-tidy version used.

As suggested in #71438 we should use
  export import std;
in the std.compat module.

Testing this locally failed when building with the clang-tidy-17
plugin. The std module was considered corrupt in the test
  libcxx/test/libcxx/module_std_compat.gen.py
however the test
  libcxx/test/libcxx/module_std.gen.py
passed. Both test generated identical std.pcm files. Using the
clang-tidy-18 plugin solves the issue.
---
 libcxx/test/tools/clang_tidy_checks/CMakeLists.txt | 4 ++--
 libcxx/utils/libcxx/test/features.py   | 4 ++--
 2 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/libcxx/test/tools/clang_tidy_checks/CMakeLists.txt 
b/libcxx/test/tools/clang_tidy_checks/CMakeLists.txt
index 260e90f45f577cb..978e70952165220 100644
--- a/libcxx/test/tools/clang_tidy_checks/CMakeLists.txt
+++ b/libcxx/test/tools/clang_tidy_checks/CMakeLists.txt
@@ -5,9 +5,9 @@
 set(LLVM_DIR_SAVE ${LLVM_DIR})
 set(Clang_DIR_SAVE ${Clang_DIR})
 
-find_package(Clang 17)
+find_package(Clang 18)
 if (NOT Clang_FOUND)
-  find_package(Clang 18)
+  find_package(Clang 17)
 endif()
 
 set(SOURCES
diff --git a/libcxx/utils/libcxx/test/features.py 
b/libcxx/utils/libcxx/test/features.py
index 6387a5c0de007bf..74c49db52d58240 100644
--- a/libcxx/utils/libcxx/test/features.py
+++ b/libcxx/utils/libcxx/test/features.py
@@ -31,8 +31,8 @@ def _getSuitableClangTidy(cfg):
 return None
 
 # TODO MODULES require ToT due module specific fixes.
-if runScriptExitCode(cfg, ['clang-tidy-17 --version']) == 0:
-  return 'clang-tidy-17'
+if runScriptExitCode(cfg, ['clang-tidy-18 --version']) == 0:
+  return 'clang-tidy-18'
 
 # TODO This should be the last stable release.
 # LLVM RELEASE bump to latest stable version

___
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++][modules] Adds module testing. (PR #76246)

2024-01-12 Thread Mark de Wever via llvm-branch-commits


@@ -156,7 +156,9 @@ export namespace std {
   using std::reinterpret_pointer_cast;
   using std::static_pointer_cast;
 
+#ifndef _LIBCPP_HAS_NO_RTTI
   using std::get_deleter;
+#endif // _LIBCPP_HAS_NO_RTTI

mordante wrote:

This tested here, but should land separately. (Currently the CI does not test 
modules so it passes.)

https://github.com/llvm/llvm-project/pull/76246
___
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++][modules] Adds module testing. (PR #76246)

2024-01-12 Thread Mark de Wever via llvm-branch-commits

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

>From eebe9b2fab5c5eef4776852270bf70af4626cfcb Mon Sep 17 00:00:00 2001
From: Mark de Wever 
Date: Wed, 20 Dec 2023 20:43:38 +0100
Subject: [PATCH] [libc++][modules] Adds module testing.

This adds a new module test infrastructure. This requires tagging tests
using modules. The test runner uses this information to determine the
compiler flags needed to build and use the module.

Currently modules are build per test, which allows testing them for
tests with ADDITIONAL_COMPILE_FLAGS. At the moment only 4 tests use
modules. Therefore the performance penalty is not measurable. If in the
future more tests use modules it would be good to measure the overhead
and determine whether it's acceptable.
---
 libcxx/docs/TestingLibcxx.rst |  9 ++-
 libcxx/modules/std/memory.inc |  2 +
 libcxx/test/libcxx/module_std.gen.py  |  1 +
 libcxx/test/libcxx/module_std_compat.gen.py   |  1 +
 .../libcxx/selftest/modules/no-modules.sh.cpp | 14 
 .../modules/std-and-std.compat-module.sh.cpp  | 22 ++
 .../libcxx/selftest/modules/std-module.sh.cpp | 24 +++
 .../selftest/modules/std.compat-module.sh.cpp | 24 +++
 libcxx/test/std/modules/std.compat.pass.cpp   |  5 +-
 libcxx/test/std/modules/std.pass.cpp  |  5 +-
 libcxx/utils/libcxx/test/features.py  | 12 
 libcxx/utils/libcxx/test/format.py| 71 +++
 libcxx/utils/libcxx/test/modules.py   |  5 +-
 13 files changed, 190 insertions(+), 5 deletions(-)
 create mode 100644 libcxx/test/libcxx/selftest/modules/no-modules.sh.cpp
 create mode 100644 
libcxx/test/libcxx/selftest/modules/std-and-std.compat-module.sh.cpp
 create mode 100644 libcxx/test/libcxx/selftest/modules/std-module.sh.cpp
 create mode 100644 libcxx/test/libcxx/selftest/modules/std.compat-module.sh.cpp

diff --git a/libcxx/docs/TestingLibcxx.rst b/libcxx/docs/TestingLibcxx.rst
index e7645cb5885f14e..50ee9d4ee400b45 100644
--- a/libcxx/docs/TestingLibcxx.rst
+++ b/libcxx/docs/TestingLibcxx.rst
@@ -394,7 +394,7 @@ Custom Directives
 ~
 
 Lit has many directives built in (e.g., ``DEFINE``, ``UNSUPPORTED``). In 
addition to those directives, libc++ adds two additional libc++-specific 
directives that makes
-writing tests easier. See `libc++-specific Lit Directives`_ for more 
information about the ``FILE_DEPENDENCIES`` and ``ADDITIONAL_COMPILE_FLAGS`` 
libc++-specific directives.
+writing tests easier. See `libc++-specific Lit Directives`_ for more 
information about the ``FILE_DEPENDENCIES``, ``ADDITIONAL_COMPILE_FLAGS``, and 
``MODULE_DEPENDENCIES`` libc++-specific directives.
 
 .. _libc++-specific Lit Directives:
 .. list-table:: libc++-specific Lit Directives
@@ -417,6 +417,13 @@ writing tests easier. See `libc++-specific Lit 
Directives`_ for more information
  - The additional compiler flags specified by a space-separated list to 
the ``ADDITIONAL_COMPILE_FLAGS`` libc++-specific Lit directive will be added to 
the end of the ``%{compile_flags}``
substitution for the test that contains it. This libc++-specific Lit 
directive makes it possible to add special compilation flags without having to 
resort to writing a ``.sh.cpp`` test (see
`Lit Meaning of libc++ Test Filenames`_), more powerful but perhaps 
overkill.
+   * - ``MODULE_DEPENDENCIES``
+ - ``// MODULE_DEPENDENCIES: std std.compat``
+ - This directive will build the required C++23 standard library
+   modules and add the additional compiler flags in
+   %{compile_flags}. (Libc++ offers these modules in C++20 as an
+   extension.)
+
 
 Benchmarks
 ==
diff --git a/libcxx/modules/std/memory.inc b/libcxx/modules/std/memory.inc
index fba2461732c1b9d..ef89845457fbb9f 100644
--- a/libcxx/modules/std/memory.inc
+++ b/libcxx/modules/std/memory.inc
@@ -156,7 +156,9 @@ export namespace std {
   using std::reinterpret_pointer_cast;
   using std::static_pointer_cast;
 
+#ifndef _LIBCPP_HAS_NO_RTTI
   using std::get_deleter;
+#endif // _LIBCPP_HAS_NO_RTTI
 
   // [util.smartptr.shared.io], shared_ptr I/O
 
diff --git a/libcxx/test/libcxx/module_std.gen.py 
b/libcxx/test/libcxx/module_std.gen.py
index 8e03d6e5b5b5235..a9a05a0cd74e614 100644
--- a/libcxx/test/libcxx/module_std.gen.py
+++ b/libcxx/test/libcxx/module_std.gen.py
@@ -30,6 +30,7 @@
 "%{test-tools}/clang_tidy_checks/libcxx-tidy.plugin",
 "%{cxx}",
 "%{flags} %{compile_flags}",
+"std",
 )
 
 
diff --git a/libcxx/test/libcxx/module_std_compat.gen.py 
b/libcxx/test/libcxx/module_std_compat.gen.py
index c4792db3d71e624..2866066ccedc89c 100644
--- a/libcxx/test/libcxx/module_std_compat.gen.py
+++ b/libcxx/test/libcxx/module_std_compat.gen.py
@@ -30,6 +30,7 @@
 "%{test-tools}/clang_tidy_checks/libcxx-tidy.plugin",
 "%{cxx}",
 "%{flags} %{compile_flags}",
+"std.compat",
 )
 
 
diff --git 

[llvm-branch-commits] [libcxx] [libc++][modules] Adds module testing. (PR #76246)

2024-01-11 Thread Mark de Wever via llvm-branch-commits


@@ -131,13 +138,65 @@ def parseScript(test, preamble):
 script += preamble
 script += scriptInTest
 
+has_std_module = False
+has_std_compat_module = False
+for module in modules:
+if module == "std":
+has_std_module = True
+elif module == "std.compat":
+has_std_compat_module = True
+else:
+script.insert(
+0,
+f"echo \"The module '{module}' is not valid, use 'std' or 
'std.compat'\"",
+)
+script.insert(1, "false")
+return script
+
+if modules:
+# This flag is needed for both modules.
+moduleCompileFlags.append("-fprebuilt-module-path=%T")

mordante wrote:

I've tested this locally and added it to this patch.

https://github.com/llvm/llvm-project/pull/76246
___
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++][modules] Adds module testing. (PR #76246)

2024-01-11 Thread Mark de Wever via llvm-branch-commits

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

>From 196cedd36534b02a7c55cf4a1746b34f87ead467 Mon Sep 17 00:00:00 2001
From: Mark de Wever 
Date: Wed, 20 Dec 2023 20:43:38 +0100
Subject: [PATCH 1/3] [libc++][modules] Adds module testing.

This adds a new module test infrastructure. This requires tagging tests
using modules. The test runner uses this information to determine the
compiler flags needed to build and use the module.

Currently modules are build per test, which allows testing them for
tests with ADDITIONAL_COMPILE_FLAGS. At the moment only 4 tests use
modules. Therefore the performance penalty is not measurable. If in the
future more tests use modules it would be good to measure the overhead
and determine whether it's acceptable.
---
 libcxx/test/libcxx/module_std.gen.py  |  3 +-
 libcxx/test/libcxx/module_std_compat.gen.py   |  3 +-
 .../libcxx/selftest/modules/no-modules.sh.cpp | 12 +++
 .../modules/std-and-std.compat-module.sh.cpp  | 23 ++
 .../libcxx/selftest/modules/std-module.sh.cpp | 25 ++
 .../selftest/modules/std.compat-module.sh.cpp | 25 ++
 .../modules/unknown-module.compile.pass.cpp   | 13 
 libcxx/test/std/modules/std.compat.pass.cpp   |  5 +-
 libcxx/test/std/modules/std.pass.cpp  |  5 +-
 libcxx/utils/libcxx/test/features.py  | 12 +++
 libcxx/utils/libcxx/test/format.py| 76 +--
 libcxx/utils/libcxx/test/modules.py   |  5 +-
 12 files changed, 196 insertions(+), 11 deletions(-)
 create mode 100644 libcxx/test/libcxx/selftest/modules/no-modules.sh.cpp
 create mode 100644 
libcxx/test/libcxx/selftest/modules/std-and-std.compat-module.sh.cpp
 create mode 100644 libcxx/test/libcxx/selftest/modules/std-module.sh.cpp
 create mode 100644 libcxx/test/libcxx/selftest/modules/std.compat-module.sh.cpp
 create mode 100644 
libcxx/test/libcxx/selftest/modules/unknown-module.compile.pass.cpp

diff --git a/libcxx/test/libcxx/module_std.gen.py 
b/libcxx/test/libcxx/module_std.gen.py
index 8e03d6e5b5b523..3ad2aff9d085f4 100644
--- a/libcxx/test/libcxx/module_std.gen.py
+++ b/libcxx/test/libcxx/module_std.gen.py
@@ -29,7 +29,8 @@
 "%{clang-tidy}",
 "%{test-tools}/clang_tidy_checks/libcxx-tidy.plugin",
 "%{cxx}",
-"%{flags} %{compile_flags}",
+"%{flags} %{compile_flags} %{module_flags}",
+"std",
 )
 
 
diff --git a/libcxx/test/libcxx/module_std_compat.gen.py 
b/libcxx/test/libcxx/module_std_compat.gen.py
index c4792db3d71e62..63fdd8188937e1 100644
--- a/libcxx/test/libcxx/module_std_compat.gen.py
+++ b/libcxx/test/libcxx/module_std_compat.gen.py
@@ -29,7 +29,8 @@
 "%{clang-tidy}",
 "%{test-tools}/clang_tidy_checks/libcxx-tidy.plugin",
 "%{cxx}",
-"%{flags} %{compile_flags}",
+"%{flags} %{compile_flags} %{module_flags}",
+"std.compat",
 )
 
 
diff --git a/libcxx/test/libcxx/selftest/modules/no-modules.sh.cpp 
b/libcxx/test/libcxx/selftest/modules/no-modules.sh.cpp
new file mode 100644
index 00..86d0afc13e3c40
--- /dev/null
+++ b/libcxx/test/libcxx/selftest/modules/no-modules.sh.cpp
@@ -0,0 +1,12 @@
+//===--===//
+//
+// 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
+//
+//===--===//
+
+// Make sure that the module flags are empty when no module is supplied.
+
+// MODULES:
+// RUN: echo "%{module_flags}"  | grep "^$"
diff --git 
a/libcxx/test/libcxx/selftest/modules/std-and-std.compat-module.sh.cpp 
b/libcxx/test/libcxx/selftest/modules/std-and-std.compat-module.sh.cpp
new file mode 100644
index 00..da9497f2dbb768
--- /dev/null
+++ b/libcxx/test/libcxx/selftest/modules/std-and-std.compat-module.sh.cpp
@@ -0,0 +1,23 @@
+//===--===//
+//
+// 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, c++20
+// UNSUPPORTED: clang-modules-build
+// UNSUPPORTED: gcc
+
+// XFAIL: has-no-module-support
+
+// Make sure that the module flags contain the expected elements.
+// The tests only look for the expected components and not the exact flags.
+// Otherwise changing the location of the module breaks this test.
+
+// MODULES: std std.compat
+//
+// RUN: echo "%{module_flags}" | grep -- "-fprebuilt-module-path="
+// RUN: echo "%{module_flags}" | grep "std.pcm"
+// RUN: echo "%{module_flags}" | grep "std.compat.pcm"
diff --git a/libcxx/test/libcxx/selftest/modules/std-module.sh.cpp 

[llvm-branch-commits] [libcxx] [libc++][modules] Adds module testing. (PR #76246)

2024-01-10 Thread Mark de Wever via llvm-branch-commits


@@ -131,13 +138,65 @@ def parseScript(test, preamble):
 script += preamble
 script += scriptInTest
 
+has_std_module = False
+has_std_compat_module = False
+for module in modules:
+if module == "std":
+has_std_module = True
+elif module == "std.compat":
+has_std_compat_module = True
+else:
+script.insert(
+0,
+f"echo \"The module '{module}' is not valid, use 'std' or 
'std.compat'\"",
+)
+script.insert(1, "false")
+return script
+
+if modules:
+# This flag is needed for both modules.
+moduleCompileFlags.append("-fprebuilt-module-path=%T")

mordante wrote:

we don't need too, but it looks better. I'll look into it.

https://github.com/llvm/llvm-project/pull/76246
___
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++][modules] Adds module testing. (PR #76246)

2024-01-10 Thread Mark de Wever via llvm-branch-commits


@@ -131,13 +138,65 @@ def parseScript(test, preamble):
 script += preamble
 script += scriptInTest
 
+has_std_module = False
+has_std_compat_module = False
+for module in modules:
+if module == "std":
+has_std_module = True
+elif module == "std.compat":
+has_std_compat_module = True
+else:
+script.insert(
+0,
+f"echo \"The module '{module}' is not valid, use 'std' or 
'std.compat'\"",
+)
+script.insert(1, "false")
+return script
+
+if modules:
+# This flag is needed for both modules.
+moduleCompileFlags.append("-fprebuilt-module-path=%T")

mordante wrote:

Thanks for the clarification. I'm not too bothered by it. In libc++ we indeed 
want to build the modules manually to avoid additional dependencies in the 
test-suite. 

https://github.com/llvm/llvm-project/pull/76246
___
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++][modules] Adds module testing. (PR #76246)

2024-01-09 Thread Mark de Wever via llvm-branch-commits

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

>From 196cedd36534b02a7c55cf4a1746b34f87ead467 Mon Sep 17 00:00:00 2001
From: Mark de Wever 
Date: Wed, 20 Dec 2023 20:43:38 +0100
Subject: [PATCH 1/2] [libc++][modules] Adds module testing.

This adds a new module test infrastructure. This requires tagging tests
using modules. The test runner uses this information to determine the
compiler flags needed to build and use the module.

Currently modules are build per test, which allows testing them for
tests with ADDITIONAL_COMPILE_FLAGS. At the moment only 4 tests use
modules. Therefore the performance penalty is not measurable. If in the
future more tests use modules it would be good to measure the overhead
and determine whether it's acceptable.
---
 libcxx/test/libcxx/module_std.gen.py  |  3 +-
 libcxx/test/libcxx/module_std_compat.gen.py   |  3 +-
 .../libcxx/selftest/modules/no-modules.sh.cpp | 12 +++
 .../modules/std-and-std.compat-module.sh.cpp  | 23 ++
 .../libcxx/selftest/modules/std-module.sh.cpp | 25 ++
 .../selftest/modules/std.compat-module.sh.cpp | 25 ++
 .../modules/unknown-module.compile.pass.cpp   | 13 
 libcxx/test/std/modules/std.compat.pass.cpp   |  5 +-
 libcxx/test/std/modules/std.pass.cpp  |  5 +-
 libcxx/utils/libcxx/test/features.py  | 12 +++
 libcxx/utils/libcxx/test/format.py| 76 +--
 libcxx/utils/libcxx/test/modules.py   |  5 +-
 12 files changed, 196 insertions(+), 11 deletions(-)
 create mode 100644 libcxx/test/libcxx/selftest/modules/no-modules.sh.cpp
 create mode 100644 
libcxx/test/libcxx/selftest/modules/std-and-std.compat-module.sh.cpp
 create mode 100644 libcxx/test/libcxx/selftest/modules/std-module.sh.cpp
 create mode 100644 libcxx/test/libcxx/selftest/modules/std.compat-module.sh.cpp
 create mode 100644 
libcxx/test/libcxx/selftest/modules/unknown-module.compile.pass.cpp

diff --git a/libcxx/test/libcxx/module_std.gen.py 
b/libcxx/test/libcxx/module_std.gen.py
index 8e03d6e5b5b523..3ad2aff9d085f4 100644
--- a/libcxx/test/libcxx/module_std.gen.py
+++ b/libcxx/test/libcxx/module_std.gen.py
@@ -29,7 +29,8 @@
 "%{clang-tidy}",
 "%{test-tools}/clang_tidy_checks/libcxx-tidy.plugin",
 "%{cxx}",
-"%{flags} %{compile_flags}",
+"%{flags} %{compile_flags} %{module_flags}",
+"std",
 )
 
 
diff --git a/libcxx/test/libcxx/module_std_compat.gen.py 
b/libcxx/test/libcxx/module_std_compat.gen.py
index c4792db3d71e62..63fdd8188937e1 100644
--- a/libcxx/test/libcxx/module_std_compat.gen.py
+++ b/libcxx/test/libcxx/module_std_compat.gen.py
@@ -29,7 +29,8 @@
 "%{clang-tidy}",
 "%{test-tools}/clang_tidy_checks/libcxx-tidy.plugin",
 "%{cxx}",
-"%{flags} %{compile_flags}",
+"%{flags} %{compile_flags} %{module_flags}",
+"std.compat",
 )
 
 
diff --git a/libcxx/test/libcxx/selftest/modules/no-modules.sh.cpp 
b/libcxx/test/libcxx/selftest/modules/no-modules.sh.cpp
new file mode 100644
index 00..86d0afc13e3c40
--- /dev/null
+++ b/libcxx/test/libcxx/selftest/modules/no-modules.sh.cpp
@@ -0,0 +1,12 @@
+//===--===//
+//
+// 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
+//
+//===--===//
+
+// Make sure that the module flags are empty when no module is supplied.
+
+// MODULES:
+// RUN: echo "%{module_flags}"  | grep "^$"
diff --git 
a/libcxx/test/libcxx/selftest/modules/std-and-std.compat-module.sh.cpp 
b/libcxx/test/libcxx/selftest/modules/std-and-std.compat-module.sh.cpp
new file mode 100644
index 00..da9497f2dbb768
--- /dev/null
+++ b/libcxx/test/libcxx/selftest/modules/std-and-std.compat-module.sh.cpp
@@ -0,0 +1,23 @@
+//===--===//
+//
+// 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, c++20
+// UNSUPPORTED: clang-modules-build
+// UNSUPPORTED: gcc
+
+// XFAIL: has-no-module-support
+
+// Make sure that the module flags contain the expected elements.
+// The tests only look for the expected components and not the exact flags.
+// Otherwise changing the location of the module breaks this test.
+
+// MODULES: std std.compat
+//
+// RUN: echo "%{module_flags}" | grep -- "-fprebuilt-module-path="
+// RUN: echo "%{module_flags}" | grep "std.pcm"
+// RUN: echo "%{module_flags}" | grep "std.compat.pcm"
diff --git a/libcxx/test/libcxx/selftest/modules/std-module.sh.cpp 

[llvm-branch-commits] [libcxx] [llvm] [libc++][modules] Adds module testing. (PR #76246)

2024-01-09 Thread Mark de Wever via llvm-branch-commits


@@ -131,13 +138,65 @@ def parseScript(test, preamble):
 script += preamble
 script += scriptInTest
 
+has_std_module = False
+has_std_compat_module = False
+for module in modules:
+if module == "std":
+has_std_module = True
+elif module == "std.compat":
+has_std_compat_module = True
+else:
+script.insert(
+0,
+f"echo \"The module '{module}' is not valid, use 'std' or 
'std.compat'\"",
+)
+script.insert(1, "false")
+return script
+
+if modules:
+# This flag is needed for both modules.
+moduleCompileFlags.append("-fprebuilt-module-path=%T")

mordante wrote:

I tested it `%T/std.compat.pcm` gives an absolute path, but it gives `fatal 
error: module 'std.compat' not found`. AFAIK this is intended. @ChuanqiXu9 do 
you want to chime in?

https://github.com/llvm/llvm-project/pull/76246
___
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++][modules] Increase clang-tidy version used. (PR #76268)

2024-01-05 Thread Mark de Wever via llvm-branch-commits

mordante wrote:

> > Then I can prohibit clang-16 and clang-17.
> 
> Yeah, that's the solution. clang-tidy defines the same version macros as 
> clang does, so prohibiting it from clang-16 is the same as prohibiting it for 
> clang-tidy 16.

What makes it currently hard for modules is that in the current situation it 
would mean modules would have about 0% coverage. 

> > IMO The biggest issue is that the clang-tidy version is hard-coded in 
> > CMake. This is something I mentioned in the past too. If it was a CMake 
> > option it would be trivial to change the value without changing 
> > CMakeList.txt.
> 
> We could also extract the clang version used and search for a clang-tidy that 
> fits this version. That would also avoid the matching problems for others. We 
> would probably have to get a path to the corresponding clang-tidy too. I 
> don't know whether that's trivially possible right now.

I think matching the version would be trivial for the additional libraries. For 
the executable it might be harder, but there we can let the user specify an 
executable and if specified test that version. Then we can issue a diagnostic 
when the versions don't match.



https://github.com/llvm/llvm-project/pull/76268
___
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++][modules] Increase clang-tidy version used. (PR #76268)

2024-01-05 Thread Mark de Wever via llvm-branch-commits

mordante wrote:

> > Oh shit. I just realized that this is most likely a latent bug no matter 
> > what. We build the module with Clang 18, and then essentially try to load 
> > it with Clang 17 (aka Clang Tidy 17). AFAIK that's not guaranteed to work, 
> > and probably just happens to work currently with Clang 17 building and 
> > Clang 18 loading the module (assuming we even test that right now?). I 
> > think we may have to always match the Clang and Clang Tidy versions we use.
> 
> I should probably keep out of these discussions but here I am:

You're welcome participate in the discussion. This is a public forum.

> Matching Clang with Clang-Tidy versions feels only natural. For instance 
> "Member visit" requires new syntax (deducing this) and fixes available in the 
> latest Clang 18 nightly, so it was surprising to find out the test failing 
> due to Clang-Tidy being used in the CI. I guess this case happens rarely but 
> this means working on library features dependant on newly implemented 
> language features might have to be postponed to the release after.

+1

> This change doesn't actually help you in this regard. We still support Clang 
> 16 and 17, so the CI would have simply failed at a later stage, but for the 
> same reason.
> 
> @mordante I'd much rather see this fixed properly than tape over it with this 
> patch.

Then I can prohibit clang-16 and clang-17. IMO The biggest issue is that the 
clang-tidy version is hard-coded in CMake. This is something I mentioned in the 
past too. If it was a CMake option it would be trivial to change the value 
without changing CMakeList.txt.


https://github.com/llvm/llvm-project/pull/76268
___
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++] Clang-tidy enable modernize-use-nullptr. (PR #76659)

2023-12-31 Thread Mark de Wever via llvm-branch-commits

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

Clang-tidy 18 no longer has false positives with the spaceship operator. Note 
that I'm quite sure there are more occurrences in our headers that are not 
caught.

>From b28cb6581a371eee5e1f06da2b4d3711b501aee3 Mon Sep 17 00:00:00 2001
From: Mark de Wever 
Date: Sun, 31 Dec 2023 14:59:46 +0100
Subject: [PATCH] [libc++] Clang-tidy enable modernize-use-nullptr.

Clang-tidy 18 no longer has false positives with the spaceship operator.
Note that I'm quite sure there are more occurrences in our headers that
are not caught.
---
 libcxx/.clang-tidy|  2 +-
 libcxx/include/__atomic/is_always_lock_free.h |  2 +-
 libcxx/include/locale | 12 ++--
 3 files changed, 8 insertions(+), 8 deletions(-)

diff --git a/libcxx/.clang-tidy b/libcxx/.clang-tidy
index 214661789cd51a..ec7cab9b878ed9 100644
--- a/libcxx/.clang-tidy
+++ b/libcxx/.clang-tidy
@@ -15,6 +15,7 @@ Checks: >
 
   modernize-loop-convert,
   modernize-redundant-void-arg,
+  modernize-use-nullptr,
   modernize-use-override,
 
   readability-duplicate-include,
@@ -68,7 +69,6 @@ CheckOptions:
 # modernize-use-default-member-init,
 # modernize-use-equals-default,
 # modernize-use-equals-delete,
-# modernize-use-nullptr,
 # portability-restrict-system-includes,
 # readability-function-cognitive-complexity,
 # readability-implicit-bool-conversion,
diff --git a/libcxx/include/__atomic/is_always_lock_free.h 
b/libcxx/include/__atomic/is_always_lock_free.h
index fbbd4370749908..f928e79f70cea3 100644
--- a/libcxx/include/__atomic/is_always_lock_free.h
+++ b/libcxx/include/__atomic/is_always_lock_free.h
@@ -20,7 +20,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD
 template 
 struct __libcpp_is_always_lock_free {
   // __atomic_always_lock_free is available in all Standard modes
-  static const bool __value = __atomic_always_lock_free(sizeof(_Tp), 0);
+  static const bool __value = __atomic_always_lock_free(sizeof(_Tp), nullptr);
 };
 
 _LIBCPP_END_NAMESPACE_STD
diff --git a/libcxx/include/locale b/libcxx/include/locale
index 70d22ff95e1ee1..9e97eb9f339533 100644
--- a/libcxx/include/locale
+++ b/libcxx/include/locale
@@ -3421,7 +3421,7 @@ wbuffer_convert<_Codecvt, _Elem, _Tr>::~wbuffer_convert() 
{
 template 
 typename wbuffer_convert<_Codecvt, _Elem, _Tr>::int_type 
wbuffer_convert<_Codecvt, _Elem, _Tr>::underflow() {
   _LIBCPP_SUPPRESS_DEPRECATED_POP
-  if (__cv_ == 0 || __bufptr_ == 0)
+  if (__cv_ == 0 || __bufptr_ == nullptr)
 return traits_type::eof();
   bool __initial = __read_mode();
   char_type __1buf;
@@ -3478,7 +3478,7 @@ template 
 typename wbuffer_convert<_Codecvt, _Elem, _Tr>::int_type
 wbuffer_convert<_Codecvt, _Elem, _Tr>::pbackfail(int_type __c) {
   _LIBCPP_SUPPRESS_DEPRECATED_POP
-  if (__cv_ != 0 && __bufptr_ != 0 && this->eback() < this->gptr()) {
+  if (__cv_ != 0 && __bufptr_ && this->eback() < this->gptr()) {
 if (traits_type::eq_int_type(__c, traits_type::eof())) {
   this->gbump(-1);
   return traits_type::not_eof(__c);
@@ -3496,7 +3496,7 @@ _LIBCPP_SUPPRESS_DEPRECATED_PUSH
 template 
 typename wbuffer_convert<_Codecvt, _Elem, _Tr>::int_type 
wbuffer_convert<_Codecvt, _Elem, _Tr>::overflow(int_type __c) {
   _LIBCPP_SUPPRESS_DEPRECATED_POP
-  if (__cv_ == 0 || __bufptr_ == 0)
+  if (__cv_ == 0 || !__bufptr_)
 return traits_type::eof();
   __write_mode();
   char_type __1buf;
@@ -3588,7 +3588,7 @@ template 
 typename wbuffer_convert<_Codecvt, _Elem, _Tr>::pos_type
 wbuffer_convert<_Codecvt, _Elem, _Tr>::seekoff(off_type __off, 
ios_base::seekdir __way, ios_base::openmode __om) {
   int __width = __cv_->encoding();
-  if (__cv_ == 0 || __bufptr_ == 0 || (__width <= 0 && __off != 0) || sync())
+  if (__cv_ == 0 || !__bufptr_ || (__width <= 0 && __off != 0) || sync())
 return pos_type(off_type(-1));
   // __width > 0 || __off == 0, now check __way
   if (__way != ios_base::beg && __way != ios_base::cur && __way != 
ios_base::end)
@@ -3601,7 +3601,7 @@ wbuffer_convert<_Codecvt, _Elem, _Tr>::seekoff(off_type 
__off, ios_base::seekdir
 template 
 typename wbuffer_convert<_Codecvt, _Elem, _Tr>::pos_type
 wbuffer_convert<_Codecvt, _Elem, _Tr>::seekpos(pos_type __sp, 
ios_base::openmode __wch) {
-  if (__cv_ == 0 || __bufptr_ == 0 || sync())
+  if (__cv_ == 0 || !__bufptr_ || sync())
 return pos_type(off_type(-1));
   if (__bufptr_->pubseekpos(__sp, __wch) == pos_type(off_type(-1)))
 return pos_type(off_type(-1));
@@ -3611,7 +3611,7 @@ wbuffer_convert<_Codecvt, _Elem, _Tr>::seekpos(pos_type 
__sp, ios_base::openmode
 template 
 int wbuffer_convert<_Codecvt, _Elem, _Tr>::sync() {
   _LIBCPP_SUPPRESS_DEPRECATED_POP
-  if (__cv_ == 0 || __bufptr_ == 0)
+  if (__cv_ == 0 || !__bufptr_)
 return 0;
   if (__cm_ & ios_base::out) {
 if (this->pptr() != this->pbase())

___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org

[llvm-branch-commits] [libcxx] [libc++] Implements filebuf unbuffered. (PR #76629)

2023-12-30 Thread Mark de Wever via llvm-branch-commits


@@ -276,6 +276,30 @@ private:
   state_type __st_;
   state_type __st_last_;
   ios_base::openmode __om_;
+  // Used to track the currently used mode and track whether the output should

mordante wrote:

Review note: It might be possible to use other fields to achieve the same goal. 
Unfortunately there's no implementation documentation for this class. This 
changes seems the simplest and the easiest to validate. 

https://github.com/llvm/llvm-project/pull/76629
___
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++] Implements filebuf unbuffered. (PR #76629)

2023-12-30 Thread Mark de Wever via llvm-branch-commits

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

When calling setbuf(nullptr, 0) before performing file operations it should set 
the file to unbuffered mode. Currently the code avoids buffering internally, 
but the underlying stream still can buffer.

This is addressed by disabling the buffering of the underlying stream.

Fixes: https://github.com/llvm/llvm-project/issues/60509

>From a68f28e4b5e2ef7c2df9ce286a747931bbf0dfe7 Mon Sep 17 00:00:00 2001
From: Mark de Wever 
Date: Sat, 30 Dec 2023 20:33:25 +0100
Subject: [PATCH] [libc++] Implements filebuf unbuffered.

When calling setbuf(nullptr, 0) before performing file operations it
should set the file to unbuffered mode. Currently the code avoids
buffering internally, but the underlying stream still can buffer.

This is addressed by disabling the buffering of the underlying stream.

Fixes: https://github.com/llvm/llvm-project/issues/60509
---
 libcxx/include/fstream|  47 ++-
 .../fstreams/filebuf.virtuals/setbuf.pass.cpp | 118 ++
 2 files changed, 164 insertions(+), 1 deletion(-)
 create mode 100644 
libcxx/test/std/input.output/file.streams/fstreams/filebuf.virtuals/setbuf.pass.cpp

diff --git a/libcxx/include/fstream b/libcxx/include/fstream
index 21fee202873e76..8a2df123486556 100644
--- a/libcxx/include/fstream
+++ b/libcxx/include/fstream
@@ -276,6 +276,30 @@ private:
   state_type __st_;
   state_type __st_last_;
   ios_base::openmode __om_;
+  // Used to track the currently used mode and track whether the output should
+  // be unbuffered.
+  // [filebuf.virtuals]/12
+  //   If setbuf(0, 0) is called on a stream before any I/O has occurred on
+  //   that stream, the stream becomes unbuffered. Otherwise the results are
+  //   implementation-defined.
+  // This allows calling setbuf(0, 0)
+  // - before opening a file,
+  // - after opening a file, before
+  //   - a read
+  //   - a write
+  //   - a seek.
+  // Note that opening a file with ios_base::ate does a seek operation.
+  // Normally underflow, overflow, and sync change this flag to
+  // ios_base::in, ios_base_out, or 0.
+  //
+  // The ios_base::trunc and ios_base::ate flags are used in the following way:
+  // - ios_base::trunc is set upon construction to indicate the unbuffered
+  //   state can be set. When requesting unbuffered output and the file is open
+  //   sets the mode. Else places a request by adding the ios_base::ate flag.
+  // - When a file is opened it checks whether both ios_base::trunc and
+  //   ios_base::ate are set. If so switches to unbuffered mode.
+  // - Using ase::ate in the open mode sets the flag to 0 so future calls to
+  //   setbuf no longer try to set the unbuffered mode.
   ios_base::openmode __cm_;
   bool __owns_eb_;
   bool __owns_ib_;
@@ -294,7 +318,10 @@ private:
   return nullptr;
 
 __om_ = __mode;
+   __try_set_unbuffered_mode();
+
 if (__mode & ios_base::ate) {
+  __cm_ = 0;
   if (fseek(__file_, 0, SEEK_END)) {
 fclose(__file_);
 __file_ = nullptr;
@@ -304,6 +331,23 @@ private:
 
 return this;
   }
+
+  _LIBCPP_HIDE_FROM_ABI void __try_set_unbuffered_mode() {
+if (__cm_ == (ios_base::trunc | ios_base::ate)) {
+  std::setbuf(__file_, nullptr);
+  __cm_ = 0;
+}
+  }
+  _LIBCPP_HIDE_FROM_ABI void __try_set_unbuffered_mode(char_type* __s, 
streamsize __n) {
+if (__cm_ == ios_base::trunc && __s == nullptr && __n == 0) {
+  if (__file_) {
+std::setbuf(__file_, nullptr);
+__cm_ = 0;
+  } else {
+__cm_ = ios_base::trunc | ios_base::ate;
+  }
+}
+  }
 };
 
 template 
@@ -319,7 +363,7 @@ basic_filebuf<_CharT, _Traits>::basic_filebuf()
   __st_(),
   __st_last_(),
   __om_(0),
-  __cm_(0),
+  __cm_(ios_base::trunc),
   __owns_eb_(false),
   __owns_ib_(false),
   __always_noconv_(false) {
@@ -780,6 +824,7 @@ template 
 basic_streambuf<_CharT, _Traits>* basic_filebuf<_CharT, 
_Traits>::setbuf(char_type* __s, streamsize __n) {
   this->setg(nullptr, nullptr, nullptr);
   this->setp(nullptr, nullptr);
+  __try_set_unbuffered_mode(__s, __n);
   if (__owns_eb_)
 delete[] __extbuf_;
   if (__owns_ib_)
diff --git 
a/libcxx/test/std/input.output/file.streams/fstreams/filebuf.virtuals/setbuf.pass.cpp
 
b/libcxx/test/std/input.output/file.streams/fstreams/filebuf.virtuals/setbuf.pass.cpp
new file mode 100644
index 00..3f561170f5fb24
--- /dev/null
+++ 
b/libcxx/test/std/input.output/file.streams/fstreams/filebuf.virtuals/setbuf.pass.cpp
@@ -0,0 +1,118 @@
+//===--===//
+//
+// 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
+//
+//===--===//
+
+// 
+

[llvm-branch-commits] [libcxx] [libc++][modules] Improves std.compat module. (PR #76330)

2023-12-27 Thread Mark de Wever via llvm-branch-commits


@@ -17,38 +17,17 @@ module;
 
 // The headers of Table 24: C++ library headers [tab:headers.cpp]
 // and the headers of Table 25: C++ headers for C library facilities 
[tab:headers.cpp.c]
-#include 
-#include 
-#include 
-#if !defined(_LIBCPP_HAS_NO_ATOMIC_HEADER)
-#  include 
-#endif
-#if !defined(_LIBCPP_HAS_NO_THREADS)
-#  include 
-#endif
-#include 
-#include 
 #include 
 #include 

mordante wrote:

I don't want to make this change in this PR and investigate it separately. I 
want to make sure it doesn't make it harder for libc++ to test our modules. I 
created a new issue for it.

https://github.com/llvm/llvm-project/pull/76330
___
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++][modules] Increase clang-tidy version used. (PR #76268)

2023-12-24 Thread Mark de Wever via llvm-branch-commits

mordante wrote:

Good point, I actually think that's true. I think we should do that in a 
separate PR. Maybe discuss it on Discord after the holidays.

https://github.com/llvm/llvm-project/pull/76268
___
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++][modules] Increase clang-tidy version used. (PR #76268)

2023-12-24 Thread Mark de Wever via llvm-branch-commits

mordante wrote:

It's the line `export import std;` in
https://github.com/llvm/llvm-project/pull/76330/files#diff-e881fdd0e6e66610142a28228b2bbf0e38520ee7186946bca06cb8d195dcd2b4

This works with Clang-17, Clang-18, and clang-tidy-18. It fails with 
clang-tidy-17. Clang-tidy tests that directly use the `std` module work. When 
importing `std` clang-tidy complains about a corrupt AST in the `std` module. 
So this sounds like a clang-tidy-17 but that has been fixed in clang-tidy-18.

https://github.com/llvm/llvm-project/pull/76268
___
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++][modules] Adds module testing. (PR #76246)

2023-12-24 Thread Mark de Wever via llvm-branch-commits

mordante wrote:

> > > If you are okay with the suggestions that I made for some typos in the 
> > > documentation, I will preemptively incorporate it into my documentation 
> > > PR.
> > 
> > 
> > Thanks for the suggestions! Please do no incorporate these in your PR. 
> > Other reviewers may have other suggestions which you then need to 
> > incorporate too. It's a lot easier, for both of us, when you finish the 
> > documentation PR and after you merged your branch I move the comments of 
> > this patch to the new location. I left this comment for other reviewers so 
> > they don't need to comment on it. This is how we typically resolve 
> > conflicts between patches.
> 
> That makes total sense. I had already added the following to my PR (in case 
> you are interested in incorporating here):
> 
> but I will gladly revert that if you think it's a good idea.

Yes otherwise we need to block your patch on this patch.

> Sorry for the confusion -- just trying to be helpful!

No problem, I appreciate your help!

https://github.com/llvm/llvm-project/pull/76246
___
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++][modules] Improves std.compat module. (PR #76330)

2023-12-24 Thread Mark de Wever via llvm-branch-commits

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

>From 6134779ac0f53ed22d8ddfc14908e595eb94fb65 Mon Sep 17 00:00:00 2001
From: Mark de Wever 
Date: Sun, 24 Dec 2023 12:13:00 +0100
Subject: [PATCH] [libc++][modules] Improves std.compat module.

Let the std.compat module use the std module instead of duplicating the
exports.

Based on @ChuanqiXu9's suggestion in #71438.
---
 libcxx/modules/std.compat.cppm.in   | 125 +---
 libcxx/modules/std.cppm.in  |   1 +
 libcxx/test/libcxx/module_std_compat.gen.py |  25 +---
 libcxx/utils/generate_libcxx_cppm_in.py |   6 +-
 libcxx/utils/libcxx/header_information.py   |  25 
 libcxx/utils/libcxx/test/format.py  |  21 ++--
 6 files changed, 44 insertions(+), 159 deletions(-)

diff --git a/libcxx/modules/std.compat.cppm.in 
b/libcxx/modules/std.compat.cppm.in
index f199e194e60b16..651d6ec7b9fe26 100644
--- a/libcxx/modules/std.compat.cppm.in
+++ b/libcxx/modules/std.compat.cppm.in
@@ -17,38 +17,17 @@ module;
 
 // The headers of Table 24: C++ library headers [tab:headers.cpp]
 // and the headers of Table 25: C++ headers for C library facilities 
[tab:headers.cpp.c]
-#include 
-#include 
-#include 
-#if !defined(_LIBCPP_HAS_NO_ATOMIC_HEADER)
-#  include 
-#endif
-#if !defined(_LIBCPP_HAS_NO_THREADS)
-#  include 
-#endif
-#include 
-#include 
 #include 
 #include 
 #include 
 #include 
 #include 
-#include 
-#include 
 #include 
 #include 
 #if !defined(_LIBCPP_HAS_NO_LOCALIZATION)
 #  include 
 #endif
 #include 
-#if !defined(_LIBCPP_HAS_NO_LOCALIZATION)
-#  include 
-#endif
-#include 
-#include 
-#include 
-#include 
-#include 
 #include 
 #include 
 #include 
@@ -65,107 +44,6 @@ module;
 #if !defined(_LIBCPP_HAS_NO_WIDE_CHARACTERS)
 #  include 
 #endif
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-#if !defined(_LIBCPP_HAS_NO_LOCALIZATION)
-#  include 
-#endif
-#include 
-#if !defined(_LIBCPP_HAS_NO_THREADS)
-#  include 
-#endif
-#include 
-#if !defined(_LIBCPP_HAS_NO_LOCALIZATION)
-#  include 
-#endif
-#if !defined(_LIBCPP_HAS_NO_LOCALIZATION)
-#  include 
-#endif
-#include 
-#if !defined(_LIBCPP_HAS_NO_LOCALIZATION)
-#  include 
-#endif
-#if !defined(_LIBCPP_HAS_NO_LOCALIZATION)
-#  include 
-#endif
-#include 
-#if !defined(_LIBCPP_HAS_NO_THREADS)
-#  include 
-#endif
-#include 
-#include 
-#if !defined(_LIBCPP_HAS_NO_LOCALIZATION)
-#  include 
-#endif
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-#if !defined(_LIBCPP_HAS_NO_LOCALIZATION)
-#  include 
-#endif
-#include 
-#include 
-#include 
-#include 
-#include 
-#if !defined(_LIBCPP_HAS_NO_LOCALIZATION)
-#  include 
-#endif
-#include 
-#if !defined(_LIBCPP_HAS_NO_THREADS)
-#  include 
-#endif
-#include 
-#if !defined(_LIBCPP_HAS_NO_THREADS)
-#  include 
-#endif
-#include 
-#include 
-#if !defined(_LIBCPP_HAS_NO_LOCALIZATION)
-#  include 
-#endif
-#include 
-#include 
-#if !defined(_LIBCPP_HAS_NO_THREADS)
-#  include 
-#endif
-#if !defined(_LIBCPP_HAS_NO_LOCALIZATION)
-#  include 
-#endif
-#include 
-#include 
-#if !defined(_LIBCPP_HAS_NO_LOCALIZATION)
-#  include 
-#endif
-#if !defined(_LIBCPP_HAS_NO_LOCALIZATION)
-#  include 
-#endif
-#include 
-#if !defined(_LIBCPP_HAS_NO_THREADS)
-#  include 
-#endif
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
 
 // *** Headers not yet available ***
 #if __has_include()
@@ -203,6 +81,7 @@ module;
 #endif // __has_include()
 
 export module std.compat;
+export import std;
+
 
-@LIBCXX_MODULE_STD_INCLUDE_SOURCES@
 @LIBCXX_MODULE_STD_COMPAT_INCLUDE_SOURCES@
\ No newline at end of file
diff --git a/libcxx/modules/std.cppm.in b/libcxx/modules/std.cppm.in
index b46c52e781f82f..6ce8e287737b88 100644
--- a/libcxx/modules/std.cppm.in
+++ b/libcxx/modules/std.cppm.in
@@ -204,4 +204,5 @@ module;
 
 export module std;
 
+
 @LIBCXX_MODULE_STD_INCLUDE_SOURCES@
diff --git a/libcxx/test/libcxx/module_std_compat.gen.py 
b/libcxx/test/libcxx/module_std_compat.gen.py
index 63fdd8188937e1..033ec34513c572 100644
--- a/libcxx/test/libcxx/module_std_compat.gen.py
+++ b/libcxx/test/libcxx/module_std_compat.gen.py
@@ -21,6 +21,7 @@
 import sys
 
 sys.path.append(sys.argv[1])
+from libcxx.header_information import module_c_headers
 from libcxx.test.modules import module_test_generator
 
 generator = module_test_generator(
@@ -37,27 +38,5 @@
 print("//--- module_std_compat.sh.cpp")
 generator.write_test(
 "std.compat",
-[
-"cassert",
-"cctype",
-"cerrno",
-"cfenv",
-"cfloat",
-"cinttypes",
-"climits",
-"clocale",
-"cmath",
-"csetjmp",
-"csignal",
-"cstdarg",
-"cstddef",
-"cstdint",
-"cstdio",
-"cstdlib",
-"cstring",
-"ctime",
-"cuchar",
-"cwchar",
-"cwctype",
-],
+

[llvm-branch-commits] [libcxx] [libc++][modules] Improves std.compat module. (PR #76330)

2023-12-24 Thread Mark de Wever via llvm-branch-commits

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

Let the std.compat module use the std module instead of duplicating the exports.

Based on @ChuanqiXu9's suggestion in #71438.

>From 246a8a14f125934b5e8c84b2d391db72ee4dc647 Mon Sep 17 00:00:00 2001
From: Mark de Wever 
Date: Sun, 24 Dec 2023 12:13:00 +0100
Subject: [PATCH] [libc++][modules] Improves std.compat module.

Let the std.compat module use the std module instead of duplicating the
exports.

Based on @ChuanqiXu9's suggestion in #71438.
---
 libcxx/modules/std.compat.cppm.in | 125 +-
 libcxx/modules/std.cppm.in|   1 +
 libcxx/test/libcxx/module_std_compat.gen.py   |  25 +---
 .../header_exportable_declarations.cpp|   2 +-
 libcxx/utils/generate_libcxx_cppm_in.py   |   6 +-
 libcxx/utils/libcxx/header_information.py |  25 
 libcxx/utils/libcxx/test/format.py|  21 ++-
 7 files changed, 45 insertions(+), 160 deletions(-)

diff --git a/libcxx/modules/std.compat.cppm.in 
b/libcxx/modules/std.compat.cppm.in
index f199e194e60b16..651d6ec7b9fe26 100644
--- a/libcxx/modules/std.compat.cppm.in
+++ b/libcxx/modules/std.compat.cppm.in
@@ -17,38 +17,17 @@ module;
 
 // The headers of Table 24: C++ library headers [tab:headers.cpp]
 // and the headers of Table 25: C++ headers for C library facilities 
[tab:headers.cpp.c]
-#include 
-#include 
-#include 
-#if !defined(_LIBCPP_HAS_NO_ATOMIC_HEADER)
-#  include 
-#endif
-#if !defined(_LIBCPP_HAS_NO_THREADS)
-#  include 
-#endif
-#include 
-#include 
 #include 
 #include 
 #include 
 #include 
 #include 
-#include 
-#include 
 #include 
 #include 
 #if !defined(_LIBCPP_HAS_NO_LOCALIZATION)
 #  include 
 #endif
 #include 
-#if !defined(_LIBCPP_HAS_NO_LOCALIZATION)
-#  include 
-#endif
-#include 
-#include 
-#include 
-#include 
-#include 
 #include 
 #include 
 #include 
@@ -65,107 +44,6 @@ module;
 #if !defined(_LIBCPP_HAS_NO_WIDE_CHARACTERS)
 #  include 
 #endif
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-#if !defined(_LIBCPP_HAS_NO_LOCALIZATION)
-#  include 
-#endif
-#include 
-#if !defined(_LIBCPP_HAS_NO_THREADS)
-#  include 
-#endif
-#include 
-#if !defined(_LIBCPP_HAS_NO_LOCALIZATION)
-#  include 
-#endif
-#if !defined(_LIBCPP_HAS_NO_LOCALIZATION)
-#  include 
-#endif
-#include 
-#if !defined(_LIBCPP_HAS_NO_LOCALIZATION)
-#  include 
-#endif
-#if !defined(_LIBCPP_HAS_NO_LOCALIZATION)
-#  include 
-#endif
-#include 
-#if !defined(_LIBCPP_HAS_NO_THREADS)
-#  include 
-#endif
-#include 
-#include 
-#if !defined(_LIBCPP_HAS_NO_LOCALIZATION)
-#  include 
-#endif
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-#if !defined(_LIBCPP_HAS_NO_LOCALIZATION)
-#  include 
-#endif
-#include 
-#include 
-#include 
-#include 
-#include 
-#if !defined(_LIBCPP_HAS_NO_LOCALIZATION)
-#  include 
-#endif
-#include 
-#if !defined(_LIBCPP_HAS_NO_THREADS)
-#  include 
-#endif
-#include 
-#if !defined(_LIBCPP_HAS_NO_THREADS)
-#  include 
-#endif
-#include 
-#include 
-#if !defined(_LIBCPP_HAS_NO_LOCALIZATION)
-#  include 
-#endif
-#include 
-#include 
-#if !defined(_LIBCPP_HAS_NO_THREADS)
-#  include 
-#endif
-#if !defined(_LIBCPP_HAS_NO_LOCALIZATION)
-#  include 
-#endif
-#include 
-#include 
-#if !defined(_LIBCPP_HAS_NO_LOCALIZATION)
-#  include 
-#endif
-#if !defined(_LIBCPP_HAS_NO_LOCALIZATION)
-#  include 
-#endif
-#include 
-#if !defined(_LIBCPP_HAS_NO_THREADS)
-#  include 
-#endif
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
 
 // *** Headers not yet available ***
 #if __has_include()
@@ -203,6 +81,7 @@ module;
 #endif // __has_include()
 
 export module std.compat;
+export import std;
+
 
-@LIBCXX_MODULE_STD_INCLUDE_SOURCES@
 @LIBCXX_MODULE_STD_COMPAT_INCLUDE_SOURCES@
\ No newline at end of file
diff --git a/libcxx/modules/std.cppm.in b/libcxx/modules/std.cppm.in
index b46c52e781f82f..6ce8e287737b88 100644
--- a/libcxx/modules/std.cppm.in
+++ b/libcxx/modules/std.cppm.in
@@ -204,4 +204,5 @@ module;
 
 export module std;
 
+
 @LIBCXX_MODULE_STD_INCLUDE_SOURCES@
diff --git a/libcxx/test/libcxx/module_std_compat.gen.py 
b/libcxx/test/libcxx/module_std_compat.gen.py
index 63fdd8188937e1..033ec34513c572 100644
--- a/libcxx/test/libcxx/module_std_compat.gen.py
+++ b/libcxx/test/libcxx/module_std_compat.gen.py
@@ -21,6 +21,7 @@
 import sys
 
 sys.path.append(sys.argv[1])
+from libcxx.header_information import module_c_headers
 from libcxx.test.modules import module_test_generator
 
 generator = module_test_generator(
@@ -37,27 +38,5 @@
 print("//--- module_std_compat.sh.cpp")
 generator.write_test(
 "std.compat",
-[
-"cassert",
-"cctype",
-"cerrno",
-"cfenv",
-"cfloat",
-"cinttypes",
-"climits",
-"clocale",
-"cmath",
-"csetjmp",
-"csignal",
-"cstdarg",
-  

[llvm-branch-commits] [libcxx] [libc++][modules] Fixes clang-tidy exports. (PR #76288)

2023-12-23 Thread Mark de Wever via llvm-branch-commits

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

As suggested in #71438 we should use
  export import std;
in the std.compat module.

Using this exports some named declarations from functions and records, adding 
them to the global namespace. Clang correctly, does not export these it's and 
issue in the declaration filtering. Declarations in function or record context 
are not considered a global named declaration.

>From dd147d317c4a1d0f9f98113106c630a1feec4320 Mon Sep 17 00:00:00 2001
From: Mark de Wever 
Date: Sat, 23 Dec 2023 15:27:43 +0100
Subject: [PATCH] [libc++][modules] Fixes clang-tidy exports.

As suggested in #71438 we should use
  export import std;
in the std.compat module.

Using this exports some named declarations from functions and records,
adding them to the global namespace. Clang correctly, does not export
these it's and issue in the declaration filtering. Declarations in
function or record context are not considered a global named
declaration.
---
 .../clang_tidy_checks/header_exportable_declarations.cpp| 6 +-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git 
a/libcxx/test/tools/clang_tidy_checks/header_exportable_declarations.cpp 
b/libcxx/test/tools/clang_tidy_checks/header_exportable_declarations.cpp
index 35f020da45c435..15d2e6839ad5e3 100644
--- a/libcxx/test/tools/clang_tidy_checks/header_exportable_declarations.cpp
+++ b/libcxx/test/tools/clang_tidy_checks/header_exportable_declarations.cpp
@@ -252,9 +252,13 @@ static bool 
is_global_name_exported_by_std_module(std::string_view name) {
 
 static bool is_valid_declaration_context(
 const clang::NamedDecl& decl, std::string_view name, 
header_exportable_declarations::FileType file_type) {
-  if (decl.getDeclContext()->isNamespace())
+  const clang::DeclContext& context = *decl.getDeclContext();
+  if (context.isNamespace())
 return true;
 
+  if (context.isFunctionOrMethod() || context.isRecord())
+return false;
+
   if (is_global_name_exported_by_std_module(name))
 return true;
 

___
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++][modules] Increase clang-tidy version used. (PR #76268)

2023-12-23 Thread Mark de Wever via llvm-branch-commits

mordante wrote:

> I'm really not happy with bumping the clang-tidy version we use all the time 
> to the trunk version. We agreed to using the latest stable version, which 
> we've not done way too many times now. I'd really like to first understand 
> what exactly the issue is that is solved by bumping the version again.

I'm also not too happy that we need to bump it, but the newest version has 
fixes I need. That patch will be 2 patches from now in this stacked review. I 
think the description of the review is clear what the issue is. Can you tell 
what's not clear?

https://github.com/llvm/llvm-project/pull/76268
___
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++][modules] Increase clang-tidy version used. (PR #76268)

2023-12-23 Thread Mark de Wever via llvm-branch-commits

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

>From 10dcb9404ac63bd1c10936e60f21159e7eabe38b Mon Sep 17 00:00:00 2001
From: Mark de Wever 
Date: Fri, 22 Dec 2023 21:43:57 +0100
Subject: [PATCH] [libc++][modules] Increase clang-tidy version used.

As suggested in #71438 we should use
  export import std;
in the std.compat module.

Testing this locally failed when building with the clang-tidy-17
plugin. The std module was considered corrupt in the test
  libcxx/test/libcxx/module_std_compat.gen.py
however the test
  libcxx/test/libcxx/module_std.gen.py
passed. Both test generated identical std.pcm files. Using the
clang-tidy-18 plugin solves the issue.
---
 libcxx/test/tools/clang_tidy_checks/CMakeLists.txt | 4 ++--
 libcxx/utils/libcxx/test/features.py   | 4 ++--
 2 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/libcxx/test/tools/clang_tidy_checks/CMakeLists.txt 
b/libcxx/test/tools/clang_tidy_checks/CMakeLists.txt
index 260e90f45f577c..978e7095216522 100644
--- a/libcxx/test/tools/clang_tidy_checks/CMakeLists.txt
+++ b/libcxx/test/tools/clang_tidy_checks/CMakeLists.txt
@@ -5,9 +5,9 @@
 set(LLVM_DIR_SAVE ${LLVM_DIR})
 set(Clang_DIR_SAVE ${Clang_DIR})
 
-find_package(Clang 17)
+find_package(Clang 18)
 if (NOT Clang_FOUND)
-  find_package(Clang 18)
+  find_package(Clang 17)
 endif()
 
 set(SOURCES
diff --git a/libcxx/utils/libcxx/test/features.py 
b/libcxx/utils/libcxx/test/features.py
index 1939d553d72dc1..36e3ff13700b8c 100644
--- a/libcxx/utils/libcxx/test/features.py
+++ b/libcxx/utils/libcxx/test/features.py
@@ -31,8 +31,8 @@ def _getSuitableClangTidy(cfg):
 return None
 
 # TODO MODULES require ToT due module specific fixes.
-if runScriptExitCode(cfg, ['clang-tidy-17 --version']) == 0:
-  return 'clang-tidy-17'
+if runScriptExitCode(cfg, ['clang-tidy-18 --version']) == 0:
+  return 'clang-tidy-18'
 
 # TODO This should be the last stable release.
 # LLVM RELEASE bump to latest stable version

___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


  1   2   >