Passing of the std::chrono::system_clock::min() time point to the std::chrono::system_clock::to_timet function results in a logical error exception being thrown and abnormal termination of the execution runtime.
This bug seems to affect Windows operating systems in general; I'm not entirely certain whether this is a bug in how the underlying operating system is exposing itself, or how the MinGW runtime for C++11 is handling the issue. The compiler & libraries however report they support this use of the chrono functions.
Here is my full code:
#include <string>
#include <iostream>
#include <chrono>
#include <ctime>
using namespace std;
using namespace std::chrono;
const string asString (const system_clock::time_point& p_TimePoint)
{
string l_timeString ("");
try
{
time_t l_time = system_clock::to_time_t(p_TimePoint);
l_timeString = ctime(&l_time);
if ( l_timeString.size() > 0 )
{
l_timeString.resize(l_timeString.size()-1);
}
}
catch (exception& l_ex)
{
cout << "Ex: " << l_ex.what() << endl;
}
return l_timeString;
}
void shoo ()
{
try
{
system_clock::time_point l_tp;
cout << "Epoch: " << asString(l_tp) << endl;
l\_tp = system\_clock::now\(\); cout << "Now: " << asString\(l\_tp\) << endl; l\_tp = system\_clock::time\_point::min\(\); cout << "Min: " << asString\(l\_tp\) << endl; l\_tp = system\_clock::time\_point::max\(\); cout << "Max: " << asString\(l\_tp\) << endl; \} catch \(exception& l\_ex\) \{ cout << "Ex: " << l\_ex.what\(\) << endl; \}
}
int main ()
{
shoo();
cout << "Done, press ENTER" << endl;
cin.get();
return 0;
}
However, you will only be interested in the line:
time_t l_time = system_clock::to_time_t(p_TimePoint);
And then only when passing in the time point:
l_tp = system_clock::time_point::min();
cout << "Min: " << asString(l_tp) << endl;
This same code works on other platforms - Ubuntu G++ for instance without problems.
My build command line parameters are very simple: g++ -x c++ -Wall -std=c++11 Test.cpp -o Test.exe
My MinGW version: Comes from "mingw-get-inst-20120426", and is 4.7.0
The C++ library in use is: libstdc++-6.dll
The gcc library in use is: libgcc_s_dw2-1.dll
My Operating System is: Windows Vista 64bit Ultimate
My machine specification is: Intel Core i7QM - 2.6ghz - 8GB DDR3 RAM - yadda yadda yadda
You may find more detailed information about this problem on my personal blog: http://megalomaniacbore.blogspot.co.uk/2012/07/mingw-c11-chrono-library-bug.html
Tracker status: I have searched the trackers for references to this problem, I have also tried to discover whether this project tracker is actually interested in STL implementation bugs like this, so please, if I'm in the wrong location, be so kind as to let me know and close the ticket. Thanks :)
View and moderate all "bugs Discussion" comments posted by this user
Mark all as spam, and block user from posting to "Issues"
My Test Code, as per post and bug tracked entry.
View and moderate all "bugs Discussion" comments posted by this user
Mark all as spam, and block user from posting to "Issues"
llibstdc++ is a GCC product. You'll most likely get better help on the bugs list for GCC. It could be an underlying problem with the MSVCRT but you'll need to chase down the origin of the stdc++ library calls to determine how the functions are implemented.
Need to research GCC bug tracker.