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

            Bug ID: 111163
           Summary: signed integer overflow in
                    std::format("{:%S}",std::chrono::duration....)
           Product: gcc
           Version: 14.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: libstdc++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: gcc at pauldreik dot se
  Target Milestone: ---

The following program:

#include <chrono>
#include <format>
int main() {
    [[maybe_unused]] auto blah = std::format(
        "{:%S}", std::chrono::duration<long, std::kilo>{2314885530818453536});
}

invokes signed integer overflow when compiled with the current gcc trunk. The
output is:
/opt/compiler-explorer/gcc-trunk-20230824/include/c++/14.0.0/bits/chrono.h:190:8:
runtime error: signed integer overflow: 2314885530818453536 * 5 cannot be
represented in type 'long int'
/opt/compiler-explorer/gcc-trunk-20230824/include/c++/14.0.0/bits/chrono.h:229:38:
runtime error: signed integer overflow: 2314885530818453536 * 5 cannot be
represented in type 'long int'

link to reproducer: https://godbolt.org/z/YWd9cx7o8

Reply via email to