https://gcc.gnu.org/bugzilla/show_bug.cgi?id=128832

            Bug ID: 128832
           Summary: Undefined behavior (signed integer overflow) when
                    formatting
                    `std::chrono::time_point::<std::chrono::system_clock>:
                    :min()`
           Product: gcc
           Version: 17.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: libstdc++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: davidfromonline at gmail dot com
  Target Milestone: ---

Given

```c++
#include <chrono>
#include <format>

auto main() -> int {
        auto _ = std::format("{}",
std::chrono::time_point<std::chrono::system_clock>::min());
}
```

and compiling with `-fsanitize=undefined`

causes

```console
ASM generation compiler returned: 0
Execution build compiler returned: 0
Program returned: 0
/cefs/8e/8e1261270580550345114ecf_gcc-trunk-20261117/include/c++/17.0.0/bits/chrono.h:231:38:
runtime error: signed integer overflow: -9223372037 * 1000000000 cannot be
represented in type 'long int'
/cefs/8e/8e1261270580550345114ecf_gcc-trunk-20261117/include/c++/17.0.0/bits/chrono.h:724:34:
runtime error: signed integer overflow: -9223372036854775808 -
9223372036709551616 cannot be represented in type 'long int'
```

See it live: https://godbolt.org/z/ce49M4ME9

Note that this also occurs when the clock is `std::chrono::file_clock`.

Reply via email to