https://gcc.gnu.org/bugzilla/show_bug.cgi?id=119141
--- Comment #2 from Nikl Kelbon <kelbonage at gmail dot com> --- (In reply to Andrew Pinski from comment #1) > ``` > #include <chrono> > #include <iostream> > > [[gnu::noinline,gnu::noipa]] > void sink(auto) > {} > > int main() { > std::chrono::milliseconds ms = std::chrono::milliseconds::max(); > std::chrono::nanoseconds ns = ms; > sink(ns); > } > ``` > > > Compile this with clang as `-std=c++23 -fsanitize=undefined -stdlib=libc++ ` > and you get the overflow at runtime too. > > GCC is not doing the constant folding at compile time and NOT ignorning the > overflow at compile time while clang is ignoring the overflow as it is done > at compile time. This is not a bug about the difference in behavior of different compilers. Of course they will behave the same, they have the same standard libraries and sanitizers. A bug in the library, this is absolutely valid code, it should not crash. The maximum number of milliseconds is IMPLICITLY cast to the maximum number of nanoseconds, this should expectedly give just the maximum number of nanoseconds without errors