[libcxx-commits] [libcxx] [libc++][chrono] Fixes (sys|local)_time formatters. (PR #76456)
Louis Dionne via libcxx-commits
libcxx-commits at lists.llvm.org
Tue Jan 16 09:39:20 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() {
----------------
ldionne wrote:
We need to test that `operator<<` has the appropriate constraints, which means that it needs to be SFINAE friendly. In other words, you want to test this via something like
```c++
template <class T>
concept is_ostreamable = requires (std::stringstream& sstr, T const& val) {
{ sstr << val; }
};
static_assert(!is_ostreamable<decltype(your-expression)>);
```
And at that point, this can be moved to `ostream.pass.cpp` or to a separate `ostream.compile.pass.cpp` (but really I think I'd leave it in the existing `.pass.cpp` as nothing more than an additional test case).
https://github.com/llvm/llvm-project/pull/76456
More information about the libcxx-commits
mailing list