[libcxx-commits] [PATCH] D138826: [libc++][chrono] Fixes formatter duration.

Eric Fiselier via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Mon Jul 10 16:46:54 PDT 2023


EricWF added inline comments.


================
Comment at: libcxx/include/__chrono/convert_to_tm.h:123
+    // conversion errors. In that case the conversion to seconds works.
+    if constexpr (is_convertible_v<_ChronoT, chrono::hours>) {
+      auto __hour      = chrono::floor<chrono::hours>(__value);
----------------
If it can't be converted to hours because it potentially overflows, why is it that converting to seconds works?




================
Comment at: libcxx/test/std/time/time.syn/formatter.duration.pass.cpp:1089
+  check(SV("06:20:44.415"), SV("{:%T}"), std::chrono::milliseconds{0x0000'fff'ffff'ffffll}); // 45 bit signed value max
+  check(SV("01:53:03"), SV("{:%T}"), std::chrono::seconds{0x0000'0003'ffff'ffffll});         // 35 bit signed value max
+  check(SV("12:15:00"), SV("{:%T}"), std::chrono::minutes{0x0fff'ffff});                     // 29 bit signed value max
----------------
EricWF wrote:
> Mordante wrote:
> > EricWF wrote:
> > > Can't we just use `std::chrono::years::max`?
> > > 
> > > Do these test cases fail before your fixes? It looks to me that they're actively avoiding constructing test values that will overflow.
> > These tests test the Standard mandated limits as stated by the comment on line 1081. Using larger values will make the tests non-portable.
> Right, but it's important we don't introduce UB if a user violates the limits (which they will). 
I don't understand where in the standard you're finding this requirement. Could you please provide the stable name?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D138826/new/

https://reviews.llvm.org/D138826



More information about the libcxx-commits mailing list