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

            Bug ID: 111162
           Summary: signed integer overflow triggered by
                    std::chrono::parse
           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>
#include <sstream>
int main() {
    std::istringstream is("21474837");
    std::chrono::minutes x;
    is >> std::chrono::parse("%8C", x);
}

invokes undefined behaviour. If compiled with the current gcc trunk, one gets
this when executed:
/opt/compiler-explorer/gcc-trunk-20230824/include/c++/14.0.0/bits/chrono_io.h:3174:20:
runtime error: signed integer overflow: 21474837 * 100 cannot be represented in
type 'int'

link to reproducer (uses gcc trunk, may go stale quick):
https://godbolt.org/z/h617GT4EY

Reply via email to