Opened 14 years ago

Closed 13 years ago

Last modified 13 years ago

#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)

datetime_mingw_convert_exception.diff (659 bytes ) - added by bley@… 14 years ago.

Download all attachments as: .zip

Change History (10)

comment:1 by Steven Watanabe, 14 years ago

Component: Nonedate_time
Owner: set to az_sw_dude

comment:2 by anonymous, 14 years ago

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).

in reply to:  2 comment:3 by Claudio Bley, 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

comment:4 by anonymous, 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.

in reply to:  4 comment:5 by anonymous, 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.

comment:6 by christian.stimming@…, 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;

in reply to:  6 comment:7 by Claudio Bley, 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

comment:8 by Andrey Semashev, 13 years ago

Resolution: fixed
Status: newclosed

(In [53622]) Fixes #2809.

comment:9 by Andrey Semashev, 13 years ago

(In [53677]) Fixes #2809.

Note: See TracTickets for help on using tickets.