No, you don't, that's why you can't fix it, much less back port it.


From: Nikl Kelbon <kelbonage@gmail.com>
Sent: Friday, March 7, 2025 6:54:27 AM
To: Tiago Freire <tmiguelf@hotmail.com>
Cc: std-proposals@lists.isocpp.org <std-proposals@lists.isocpp.org>
Subject: Re: [std-proposals] Chrono API provokes errors

We not even have a way to make it without overflow in standard. Its just bug and should be back ported

пт, 7 мар. 2025 г. в 09:49, Tiago Freire <tmiguelf@hotmail.com>:
It's not an error, it's an overflow.

You are trying to put a larger thing into a smaller thing, it won't fit. And this larger thing is implantation defined on purpose.
Something must give.

You can only make it somewhat more well-behaved if you say that the conversion saturates. Which is better than nothing, it would still not make things portable.



From: Std-Proposals <std-proposals-bounces@lists.isocpp.org> on behalf of Nikl Kelbon via Std-Proposals <std-proposals@lists.isocpp.org>
Sent: Friday, March 7, 2025 4:50:12 AM
To: std-proposals <std-proposals@lists.isocpp.org>
Cc: Nikl Kelbon <kelbonage@gmail.com>
Subject: [std-proposals] Chrono API provokes errors

Lets say programmer want to create timeout (seconds) and want to use max() as default (means never). Obvious (and the obvious (and seemingly only) way to try to do this):

#include <chrono>

void do_work(std::chrono::nanoseconds timeout) {
  /* do smth */
}

int main() {
    std::chrono::seconds my_timeout(std::chrono::seconds::max());
    do_work(my_timeout);
}

Turns out, it IS undefined behavior. Where? In IMPLICIT conversation from seconds to nanoseconds! Timeout in 'do_work' is garbage now!

https://godbolt.org/z/rjqoWr9q4

For me its obvious, that its standard library bug and standard must say what is expected behavior for this