[libcxx-commits] [libcxx] [libc++][chrono] Loads tzdata.zi in tzdb. (PR #74928)

Louis Dionne via libcxx-commits libcxx-commits at lists.llvm.org
Tue Feb 6 11:29:34 PST 2024


================
@@ -0,0 +1,35 @@
+//===----------------------------------------------------------------------===//
+//
+// 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 time_zone_link;
+
+// string_view name()   const noexcept;
+
+#include <cassert>
+#include <chrono>
+
+#include "test_macros.h"
+
+int main(int, const char**) {
+  const std::chrono::tzdb& tzdb = std::chrono::get_tzdb();
+  assert(tzdb.links.size() > 1);
+
+  [[maybe_unused]] std::same_as<std::string_view> auto _ = tzdb.links[0].name();
----------------
ldionne wrote:

This style of writing with `_` and `[[maybe_unused]]` seems unnecessary to me -- why not instead keep it as `name = tzdb.links[0].name()` and write `assert(name != tzdb.links[1].name())` below? In addition we're ensuring that `name` is valid across multiple statements. For example if we somehow returned a dangling ref, the test on line 32 would likely work cause it's all happening inside the same expression.

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


More information about the libcxx-commits mailing list