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

via libcxx-commits libcxx-commits at lists.llvm.org
Tue Mar 26 15:54:19 PDT 2024


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

We can also test that we correctly construct the leap second for the min/max values it supports.

We should always test the edge cases, especially when integer overflow is potentially involved. That way UBSAN can flag the bugs for us.

As for the issues with runtime testing using the DB vs compile time testing of the types, I actually think we need to separate out the runtime DB testing into a separate testable unit that we can manipulate outside of the constraints of the standard (specifically that we read a specific file from a hardcoded location). 

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


More information about the libcxx-commits mailing list