Search code examples
c++stdassertc++-chrono

g++ std::chrono assertion break


I'm having trouble with some code from a C++ project. It includes the std::chrono library and keeps breaking at the following assertion:

static_assert(system_clock::duration::min() < system_clock::duration::zero(), "a clock's minimum duration cannot be less than its epoch");

The assert breaks the code in both a Debian machine with g++ 6.3.0 and in a PC with Windows 10, CygWin and g++ 7.3.0. I've also tried in an online C++ compiler a simple example including the chrono library, which by itself does not give any problems, but when comparing manually the minimum and zero duration of the chrono system clock gives the result that should trigger the assert as well.

I've searched about the issue and found some clues leading to some related problems caused by the TZ posix variable that holds timezone info. Tried unsetting and setting it to its right value, yet it had no effects on the assert.

I'd appreciate any pointers or suggestions.

Edit: While std::chrono::milliseconds::zero() has a (as expected) value of 0, the value of std::chrono::milliseconds::min() is -9223372036854775808, or -2^63 which i think is the minimum possible value for a long long value (possible overflow?).


Solution

  • After some tests i realized the assert was being triggered in both systems only when using the g++ through the testing software being used, since the same code compiled outside it did not fail the assertion with the same compilers.

    It turns out that the software uses the EDG parser and it needs the option --64_bit_target to avoid triggering the assert. Unfortunately, no information about the option exists in the parser documentation, so i can't know the reason why this issue happens without it.

    Probably the question doesn't have much value now, but i didn't want to delete it since people already wrote answers that may be of interest to someone.