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

            Bug ID: 126524
           Summary: chrono::round<nanoseconds>(nanoseconds::max())
                    triggers integer overflow
           Product: gcc
           Version: 16.1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: libstdc++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: rs2740 at gmail dot com
  Target Milestone: ---

#include <chrono>
using namespace std::chrono;

int main() {
    (void) round<nanoseconds>(nanoseconds::max());
}

will error with -fsanitize=undefined:

/cefs/38/383ad2f84cbd57a52fd68bbe_consolidated/compilers_c++_x86_gcc_16.1.0/include/c++/16.1.0/bits/chrono.h:706:34:
runtime error: signed integer overflow: 9223372036854775807 + 1 cannot be
represented in type 'long int'
/cefs/38/383ad2f84cbd57a52fd68bbe_consolidated/compilers_c++_x86_gcc_16.1.0/include/c++/16.1.0/bits/chrono.h:720:34:
runtime error: signed integer overflow: -9223372036854775808 -
9223372036854775807 cannot be represented in type 'long int'

I don't see anything in https://eel.is/c++draft/time.duration.cast#9 that bans
this.

Reply via email to