Workaround a bug in libstdc++
diff --git a/include/fmt/chrono.h b/include/fmt/chrono.h
index a1e6758..95ae26e 100644
--- a/include/fmt/chrono.h
+++ b/include/fmt/chrono.h
@@ -23,6 +23,17 @@
#include "format.h"
namespace fmt_detail {
+struct time_zone {
+ template <typename Duration, typename T>
+ auto to_sys(T)
+ -> std::chrono::time_point<std::chrono::system_clock, Duration> {
+ return {};
+ }
+};
+template <typename... T> inline auto current_zone(T...) -> time_zone* {
+ return nullptr;
+}
+
template <typename... T> inline void _tzset(T...) {}
} // namespace fmt_detail
@@ -507,6 +518,14 @@
time_point.time_since_epoch())
.count();
}
+
+// Workaround a bug in libstc++ which sets __cpp_lib_chrono to 201907 without
+// providing current_zone(): https://github.com/fmtlib/fmt/issues/4160.
+template <typename T> FMT_CONSTEXPR auto has_current_zone() -> bool {
+ using namespace std::chrono;
+ using namespace fmt_detail;
+ return !std::is_same<decltype(current_zone()), fmt_detail::time_zone*>::value;
+}
} // namespace detail
FMT_BEGIN_EXPORT
@@ -553,10 +572,12 @@
}
#if FMT_USE_LOCAL_TIME
-template <typename Duration>
+template <typename Duration,
+ FMT_ENABLE_IF(detail::has_current_zone<Duration>())>
inline auto localtime(std::chrono::local_time<Duration> time) -> std::tm {
- return localtime(
- detail::to_time_t(std::chrono::current_zone()->to_sys(time)));
+ using namespace std::chrono;
+ using namespace fmt_detail;
+ return localtime(detail::to_time_t(current_zone()->to_sys<Duration>(time)));
}
#endif
@@ -1559,9 +1580,8 @@
FMT_CONSTEXPR void on_iso_time() {}
FMT_CONSTEXPR void on_am_pm() {}
FMT_CONSTEXPR void on_duration_value() const {
- if (has_precision_integral) {
+ if (has_precision_integral)
FMT_THROW(format_error("precision not allowed for this argument type"));
- }
}
FMT_CONSTEXPR void on_duration_unit() {}
};
diff --git a/include/fmt/xchar.h b/include/fmt/xchar.h
index a43530f..da593d3 100644
--- a/include/fmt/xchar.h
+++ b/include/fmt/xchar.h
@@ -117,8 +117,7 @@
template <> struct is_char<char32_t> : std::true_type {};
#ifdef __cpp_char8_t
-template <>
-struct is_char<char8_t> : bool_constant<detail::is_utf8_enabled> {};
+template <> struct is_char<char8_t> : bool_constant<detail::is_utf8_enabled> {};
#endif
template <typename... T>