Modify

Opened 9 years ago

Closed 8 years ago

Last modified 8 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@… 9 years ago.

Download all attachments as: .zip

Change History (10)

Changed 9 years ago by bley@…

comment:1 Changed 9 years ago by Steven Watanabe

Component: Nonedate_time
Owner: set to az_sw_dude

comment:2 Changed 9 years ago by 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).

comment:3 in reply to:  2 Changed 9 years ago by Claudio Bley

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 Changed 9 years ago by 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.

comment:5 in reply to:  4 Changed 9 years ago by anonymous

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 Changed 9 years ago by christian.stimming@…

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 in reply to:  6 Changed 8 years ago by Claudio Bley

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 Changed 8 years ago by Andrey Semashev

Resolution: fixed
Status: newclosed

(In [53622]) Fixes #2809.

comment:9 Changed 8 years ago by Andrey Semashev

(In [53677]) Fixes #2809.

Modify Ticket

Change Properties
Set your email in Preferences
Action
as closed The owner will remain az_sw_dude.
The resolution will be deleted.

Add Comment


E-mail address and name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.