我认为我已经在GCC的std::chrono::duration_cast实现中发现了一个bug。请有人确认一下吗?
测试代码:
using Ticks = std::chrono::duration<long long, std::ratio_multiply<std::chrono::nanoseconds::period, std::ratio<100>>>;
using dur = typename std::chrono::system_clock::duration;
int main()
{
std::chrono::time_point<std::chrono::system_clock> earliest {std::chrono::duration_cast<dur>(
std::chrono::time_point<std::chrono::system_clock, Ticks>::max().time_since_epoch())};
auto ticks = std::chrono::time_point<std::chrono::system_clock, Ticks>::max().time_since_epoch().count();
std::cout << "Ticks: " << ticks << "\n";
std::cout << sizeof(earliest.time_since_epoch().count()) << "\n";
std::cout << "Microseconds: " << earliest.time_since_epoch().count() << "\n";
std::time_t t = std::chrono::system_clock::to_time_t(earliest);
std::cout << "earliest:\n" << std::ctime(&t);
}
使用clang 3.8的输出结果为:
Ticks: 9223372036854775807
8
Microseconds: 922337203685477580
earliest:
Sun Sep 14 02:48:05 31197
使用GCC 7.1输出结果为:
Ticks: 9223372036854775807
8
Microseconds: -100
earliest:
Thu Jan 1 00:00:00 1970
我错了吗?