On Wed, Dec 2, 2026 at 11:08 PM Jonathan Wakely <[email protected]> wrote:

> For a ratio<1, (1<<n)> where the value cannot be accurately represented
> in 18 decimal digits, we were setting fractional_width to 18 instead of
> to 6 as required by the standard.
>
> libstdc++-v3/ChangeLog:
>
>         * include/std/chrono (hh_mm_ss::_S_fractional_width): Return 6
>         when the value cannot be accurately represented in 18 decimal
>         digits.
>         * testsuite/libstdc++-prettyprinters/chrono.cc: Test more cases.
>         * testsuite/std/time/hh_mm_ss/1.cc: Check for correct value of
>         fractional_width.
> ---
>
> This has been wrong since the initial commit of chrono::hh_mm_ss.
>
LGTM

>
> Tested x86_64-linux.
>
>  libstdc++-v3/include/std/chrono                     |  2 +-
>  .../testsuite/libstdc++-prettyprinters/chrono.cc    | 13 ++++++++++++-
>  libstdc++-v3/testsuite/std/time/hh_mm_ss/1.cc       |  4 +++-
>  3 files changed, 16 insertions(+), 3 deletions(-)
>
> diff --git a/libstdc++-v3/include/std/chrono
> b/libstdc++-v3/include/std/chrono
> index 6244a31fd5f0..57b7a5accc6b 100644
> --- a/libstdc++-v3/include/std/chrono
> +++ b/libstdc++-v3/include/std/chrono
> @@ -2344,7 +2344,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
>           int __width = (__multiplicity_2 > __multiplicity_5
>                          ? __multiplicity_2 : __multiplicity_5);
>           if (__width > 18)
> -           __width = 18;
> +           __width = 6;
>           return __width;
>         }
>
> diff --git a/libstdc++-v3/testsuite/libstdc++-prettyprinters/chrono.cc
> b/libstdc++-v3/testsuite/libstdc++-prettyprinters/chrono.cc
> index a668d9699277..b7d52c21d0e6 100644
> --- a/libstdc++-v3/testsuite/libstdc++-prettyprinters/chrono.cc
> +++ b/libstdc++-v3/testsuite/libstdc++-prettyprinters/chrono.cc
> @@ -80,13 +80,24 @@ main()
>    // { dg-final { note-test nam0 {0 is not a valid month} } }
>    [[maybe_unused]] weekday nawd(8);
>    // { dg-final { note-test nawd {8 is not a valid weekday} } }
> -  //
> +
>    hh_mm_ss<seconds> hms(4h + 3min + 2s);
>    // { dg-final { note-test hms {04:03:02} } }
>
>    hh_mm_ss<nanoseconds> hms_nano(-14h - 13min - 12s - 11ns);
>    // { dg-final { note-test hms_nano {-14:13:12.000000011} } }
>
> +  hh_mm_ss<duration<long, std::ratio<60>>> hms_mins(6h + 7min);
> +  // { dg-final { note-test hms_mins {06:07:00} } }
> +
> +  using Frames = duration<long, std::ratio<1, 24>>;
> +  hh_mm_ss<Frames> hms_frames(1h + 2min + 3s + Frames(23));
> +  // { dg-final { note-test hms_frames {01:02:03.958333} } }
> +
> +  using D_2_19 = duration<long long, std::ratio<1, (1<<19)>>;
> +  hh_mm_ss<D_2_19> hms_d_2_19(11h + 12min + 13s + D_2_19(1 << 15));
> +  // { dg-final { note-test hms_d_2_19 {11:12:13.062500} } }
> +
>    std::cout << "\n";
>    return 0;                    // Mark SPOT
>  }
> diff --git a/libstdc++-v3/testsuite/std/time/hh_mm_ss/1.cc
> b/libstdc++-v3/testsuite/std/time/hh_mm_ss/1.cc
> index adf24f719130..b956b1fe4189 100644
> --- a/libstdc++-v3/testsuite/std/time/hh_mm_ss/1.cc
> +++ b/libstdc++-v3/testsuite/std/time/hh_mm_ss/1.cc
> @@ -44,8 +44,10 @@ constexpr_hh_mm_ss()
>    static_assert(hh_mm_ss<duration<int, ratio<1, 9>>>::fractional_width ==
> 6);
>    static_assert(hh_mm_ss<duration<int, ratio<1, 10>>>::fractional_width
> == 1);
>    static_assert(hh_mm_ss<duration<int, ratio<756,
> 625>>>::fractional_width == 4);
> +  static_assert(hh_mm_ss<duration<int, ratio<1, (1ll <<
> 19)>>>::fractional_width
> +               == 6);
>    static_assert(hh_mm_ss<duration<int, ratio<1, (1ll <<
> 62)>>>::fractional_width
> -               == 18);
> +               == 6);
>
>    constexpr auto hms = hh_mm_ss{-(8h + 9min + 10s + 11ms + 12us + 13ns)};
>    static_assert(__is_same(decltype(hms)::precision, nanoseconds));
> --
> 2.56.1
>
>

Reply via email to