[Bug libstdc++/95992] chrono adding duration to time_point reports signed integer overflow with -fsanitize=undefined
redi at gcc dot gnu.org
gcc-bugzilla@gcc.gnu.org
Tue Jun 30 23:18:01 GMT 2020
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95992
Jonathan Wakely <redi at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Resolution|--- |INVALID
Status|UNCONFIRMED |RESOLVED
--- Comment #1 from Jonathan Wakely <redi at gcc dot gnu.org> ---
I don't think there's any bug here. Libstdc++ uses nanoseconds for
chrono::system_clock::duration, but libc++ uses microseconds.
If you replace system_clock with high_resolution_clock you get the same error
with both libstdc++ and libc++, and the reason is that 9 billion seconds cannot
be represented in nanoseconds.
You need to use more suitable types for the durations you're trying to deal
with, e.g.
using duration_t = std::chrono::microseconds;
void test() {
std::chrono::time_point<std::chrono::system_clock, duration_t> tp;
More information about the Gcc-bugs
mailing list