Closed tomaszkam closed 5 years ago
It does not look like we can avoid undefined behavior in this case, without performing major change to the implementation of functions like: https://github.com/HowardHinnant/date/blob/ed0368fc75427ef05cefdf19a39b60d7bed2f039/include/date/date.h#L2150-L2153 Thus I think, we would need to make behavior of such arithmetic undefined.
Tim's Song comment:
Additionally, the reference implementation is susceptible to integral overflow for very large values of dm, though the actual result in such cases will be outside the representable range of year_month anyway in all implementations that do not use 20-bit signed integers for months. I don't know if we want to make a "not UB" promise in this case. For comparison, month arithmetic will never have UB unless months::rep is at least as big as long long (see also https://github.com/cplusplus/draft/issues/1974).
I think we can close this. Yes, overflow is a problem. However it is an existing issue within the <chrono>
library since C++11. The status-quo throughout <chrono>
is to just let what happens happen. If we want to say something more chrono-wide, we should do it in C++23.
Close it as the extension (EXT) or just not/no longer a defect (NAD)?
The LWG issues list has something called NAD-Future. It means there is a suggestion that we might revisit this issue for a future standard. Maybe that would be appropriate here.
Ok, closed with NAD but added LWG-issues tag.
Original comment:
Suggestion:
Email conversation (reflector): [isocpp-lib] year_month arithmetic