Modify

Ticket #2809 (closed Bugs: fixed)

Opened 5 years ago

Last modified 5 years ago

[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

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

Change History

Changed 5 years ago by bley@…

comment:1 Changed 5 years ago by steven_watanabe

  • Owner set to az_sw_dude
  • Component changed from None to date_time

comment:2 follow-up: ↓ 3 Changed 5 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 5 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 follow-up: ↓ 5 Changed 5 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 5 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 follow-up: ↓ 7 Changed 5 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 5 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 5 years ago by andysem

  • Status changed from new to closed
  • Resolution set to fixed

(In [53622]) Fixes #2809.

comment:9 Changed 5 years ago by andysem

(In [53677]) Fixes #2809.

View

Add a comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
The resolution will be deleted. Next status will be 'reopened'
Author


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

 
Note: See TracTickets for help on using tickets.