[libcxx-commits] [libcxx] [libc++][chrono] Fixes (sys|local)_time formatters. (PR #76456)

Mark de Wever via libcxx-commits libcxx-commits at lists.llvm.org
Sun Jan 21 12:03:39 PST 2024


================
@@ -0,0 +1,83 @@
+//===----------------------------------------------------------------------===//
+//
+// 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-localization
+// UNSUPPORTED: GCC-ALWAYS_INLINE-FIXME
+
+// TODO FMT This test should not require std::to_chars(floating-point)
+// XFAIL: availability-fp_to_chars-missing
+
+// <chrono>
+
+// class system_clock;
+
+// template<class charT, class traits, class Duration>
+//   basic_ostream<charT, traits>&
+//     operator<<(basic_ostream<charT, traits>& os, const local_time<Duration>& tp);
+
+// The function uses the system_clock which has two overloads
+
+// template<class charT, class traits, class Duration>
+//   basic_ostream<charT, traits>&
+//     operator<<(basic_ostream<charT, traits>& os, const sys_time<Duration>& tp);
+// Constraints: treat_as_floating_point_v<typename Duration::rep> is false, and Duration{1} < days{1} is true.
+
+// template<class charT, class traits>
+//   basic_ostream<charT, traits>&
+//     operator<<(basic_ostream<charT, traits>& os, const sys_days& dp);
+
+#include <chrono>
+#include <ratio>
+#include <sstream>
+#include <type_traits>
+
+void test() {
----------------
mordante wrote:

Actually that won't work. The `operator<<` is not constrained. For `sys_time` the `operator<<` is constrained. But this operator is defined as
```[time.clock.local]/2
Effects: os << sys_time<Duration>{lt.time_since_epoch()};
```
Note the wording is `Effects:` not `Effects: Equivalent to`, the latter would constrain the function, the former doesn't. Both MSVC STL and libstdc++ agree; local_time can not be SFINAE tested, system_time can. I'll leave a comment in the code instead.

At the LWG reflector Jonathan brought up a discussion about this issue and I've added this information. For now I want to see how that discussion pans out and whether an LWG issue should be filed.


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


More information about the libcxx-commits mailing list