#2809 closed Bugs (fixed)
[patch] Date Time exception with MinGW
Reported by: | Claudio Bley | Owned by: | az_sw_dude |
---|---|---|---|
Milestone: | Boost 1.39.0 | Component: | date_time |
Version: | Boost 1.38.0 | Severity: | Problem |
Keywords: | Cc: |
Description
Hi.
I'm using Boost version 1.38 under Windows using MinGW.
When trying to use the this_thread::sleep function I got the following exception:
"could not convert calendar time to UTC time"
During compilation I received the following compiler warning:
../../../../boost/date_time/filetime_functions.hpp: In function `uint64_t boost::date_time::winapi::file_time_to_microseconds(const FileTimeT&)': ../../../../boost/date_time/filetime_functions.hpp:101: warning: left shift count >= width of type
regarding the following code:
const uint64_t c1 = 27111902UL; const uint64_t c2 = 3577643008UL; const uint64_t shift = (c1 << (32)) + c2; // issues warning without 'UL'
It seems GCC over-optimizes this case as it replaces the variables with the corresponding literal values. Since 27111902UL is just an unsigned long (not an unsigned long long) it is only 32 bit wide (on my machine) -- leading to the compiler warning above.
To fix this issue, the literals need to be written using the ULL suffix or the suggested patch (attached) needs to be applied.
Regards, Claudio
Attachments (1)
Change History (10)
by , 14 years ago
Attachment: | datetime_mingw_convert_exception.diff added |
---|
comment:1 by , 14 years ago
Component: | None → date_time |
---|---|
Owner: | set to |
follow-up: 3 comment:2 by , 14 years ago
comment:3 by , 14 years ago
Hi.
Replying to anonymous:
As noted by Bruno Dutra on the Boost Users mailing list ("Exception: could not convert calendar time to UTC time"), the exception problem can be solved by replacing the type of the variable micros by std::time_t (boost/date_time/microsec_time_clock.hpp, revision 49874, line 90).
Granted, this prevents the exception -- but microsec_clock::create_time() returns entirely wrong results.
cout << boost::posix_time::microsec_clock::local_time() << endl;
Result:
1970-Jan-01 01:43:38.138948
And, no, my system date is not set to 1970-Jan-01. ;)
Regards, Claudio
follow-up: 5 comment:4 by , 13 years ago
Will Claudio's patch be included in the next release? Using the patch on my Windows CP machine and MinGW works like a charm.
comment:5 by , 13 years ago
Replying to anonymous:
Will Claudio's patch be included in the next release? Using the patch on my Windows CP machine and MinGW works like a charm.
Sorry for the typo, should be Windows XP.
follow-up: 7 comment:6 by , 13 years ago
I can confirm both the problem (mingw, gcc-3.4.2) and its proposed solution. As an alternative to the patch above, the change below would fix the warning as well. Please please include it in SVN, thanks a lot!
--- filetime_functions.hpp~ Wed May 13 12:13:16 2009 +++ filetime_functions.hpp Wed May 13 18:35:09 2009 @@ -98,7 +98,7 @@ * in 100-nanosecond intervals */ const uint64_t c1 = 27111902UL; const uint64_t c2 = 3577643008UL; // issues warning without 'UL' - const uint64_t shift = (c1 << 32) + c2; + const uint64_t shift = (uint64_t(c1) << 32) + c2; union { FileTimeT as_file_time;
comment:7 by , 13 years ago
Replying to christian.stimming@ibeo-as.com:
As an alternative to the patch above, the change below would fix the warning as well.
I can't confirm that your patch works. Contrary, I still get the warning as well as the exception.
Regards, Claudio
As noted by Bruno Dutra on the Boost Users mailing list ("Exception: could not convert calendar time to UTC time"), the exception problem can be solved by replacing the type of the variable micros by std::time_t (boost/date_time/microsec_time_clock.hpp, revision 49874, line 90).