[libcxx-commits] [libcxx] [libc++][chrono] Fix streaming for unsigned durations. (PR #97889)

Mark de Wever via libcxx-commits libcxx-commits at lists.llvm.org
Tue Jul 9 22:57:26 PDT 2024


================
@@ -589,9 +590,14 @@ __format_chrono(const _Tp& __value,
     __sstr << __value;
   else {
     if constexpr (chrono::__is_duration<_Tp>::value) {
-      if (__value < __value.zero())
-        __sstr << _CharT('-');
-      __formatter::__format_chrono_using_chrono_specs(__sstr, chrono::abs(__value), __chrono_specs);
+      if constexpr (numeric_limits<typename _Tp::rep>::is_signed) {
----------------
mordante wrote:

Actually there is a difference between the two. Users may specialize `numeric_limits`, but specializing `is_signed` is not allowed. Durations can use a user defined arithmetic type. So using  `numeric_limits` seems to be the better choice. I've added comment in the code.

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


More information about the libcxx-commits mailing list