Boost C++ Libraries: Ticket #2809: [patch] Date Time exception with MinGW https://svn.boost.org/trac10/ticket/2809 <p> Hi. </p> <p> I'm using Boost version 1.38 under Windows using MinGW. </p> <p> When trying to use the this_thread::sleep function I got the following exception: </p> <p> "could not convert calendar time to UTC time" </p> <p> During compilation I received the following compiler warning: </p> <pre class="wiki">../../../../boost/date_time/filetime_functions.hpp: In function `uint64_t boost::date_time::winapi::file_time_to_microseconds(const FileTimeT&amp;)': ../../../../boost/date_time/filetime_functions.hpp:101: warning: left shift count &gt;= width of type </pre><p> regarding the following code: </p> <div class="wiki-code"><div class="code"><pre><span class="k">const</span> <span class="kt">uint64_t</span> <span class="n">c1</span> <span class="o">=</span> <span class="mi">27111902UL</span><span class="p">;</span> <span class="k">const</span> <span class="kt">uint64_t</span> <span class="n">c2</span> <span class="o">=</span> <span class="mi">3577643008UL</span><span class="p">;</span> <span class="k">const</span> <span class="kt">uint64_t</span> <span class="n">shift</span> <span class="o">=</span> <span class="p">(</span><span class="n">c1</span> <span class="o">&lt;&lt;</span> <span class="p">(</span><span class="mi">32</span><span class="p">))</span> <span class="o">+</span> <span class="n">c2</span><span class="p">;</span> <span class="c1">// issues warning without &#39;UL&#39;</span> </pre></div></div><p> It seems GCC over-optimizes this case as it replaces the variables with the corresponding literal values. Since 27111902UL is just an <strong>unsigned long</strong> (not an <strong>unsigned long long</strong>) it is only 32 bit wide (on my machine) -- leading to the compiler warning above. </p> <p> To fix this issue, the literals need to be written using the ULL suffix or the suggested patch (attached) needs to be applied. </p> <p> Regards, Claudio </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/2809 Trac 1.4.3 bley@… Fri, 27 Feb 2009 15:41:09 GMT attachment set https://svn.boost.org/trac10/ticket/2809 https://svn.boost.org/trac10/ticket/2809 <ul> <li><strong>attachment</strong> → <span class="trac-field-new">datetime_mingw_convert_exception.diff</span> </li> </ul> Ticket Steven Watanabe Fri, 27 Feb 2009 17:36:48 GMT component changed; owner set https://svn.boost.org/trac10/ticket/2809#comment:1 https://svn.boost.org/trac10/ticket/2809#comment:1 <ul> <li><strong>owner</strong> set to <span class="trac-author">az_sw_dude</span> </li> <li><strong>component</strong> <span class="trac-field-old">None</span> → <span class="trac-field-new">date_time</span> </li> </ul> Ticket anonymous Thu, 05 Mar 2009 15:42:03 GMT <link>https://svn.boost.org/trac10/ticket/2809#comment:2 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/2809#comment:2</guid> <description> <p> 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). </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Claudio Bley</dc:creator> <pubDate>Mon, 09 Mar 2009 09:42:32 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/2809#comment:3 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/2809#comment:3</guid> <description> <p> Hi. </p> <p> Replying to <a class="ticket" href="https://svn.boost.org/trac10/ticket/2809#comment:2" title="Comment 2">anonymous</a>: </p> <blockquote class="citation"> <p> 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). </p> </blockquote> <p> Granted, this prevents the exception -- but microsec_clock::create_time() returns entirely wrong results. </p> <div class="wiki-code"><div class="code"><pre><span class="n">cout</span> <span class="o">&lt;&lt;</span> <span class="n">boost</span><span class="o">::</span><span class="n">posix_time</span><span class="o">::</span><span class="n">microsec_clock</span><span class="o">::</span><span class="n">local_time</span><span class="p">()</span> <span class="o">&lt;&lt;</span> <span class="n">endl</span><span class="p">;</span> </pre></div></div><p> Result: </p> <pre class="wiki">1970-Jan-01 01:43:38.138948 </pre><p> And, no, my system date is not set to 1970-Jan-01. ;) </p> <p> Regards, Claudio </p> </description> <category>Ticket</category> </item> <item> <dc:creator>anonymous</dc:creator> <pubDate>Wed, 06 May 2009 14:47:26 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/2809#comment:4 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/2809#comment:4</guid> <description> <p> Will Claudio's patch be included in the next release? Using the patch on my Windows CP machine and MinGW works like a charm. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>anonymous</dc:creator> <pubDate>Wed, 06 May 2009 14:48:54 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/2809#comment:5 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/2809#comment:5</guid> <description> <p> Replying to <a class="ticket" href="https://svn.boost.org/trac10/ticket/2809#comment:4" title="Comment 4">anonymous</a>: </p> <blockquote class="citation"> <p> Will Claudio's patch be included in the next release? Using the patch on my Windows CP machine and MinGW works like a charm. </p> </blockquote> <p> Sorry for the typo, should be Windows XP. </p> </description> <category>Ticket</category> </item> <item> <author>christian.stimming@…</author> <pubDate>Wed, 13 May 2009 18:53:10 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/2809#comment:6 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/2809#comment:6</guid> <description> <p> 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! </p> <pre class="wiki">--- 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 &lt;&lt; 32) + c2; + const uint64_t shift = (uint64_t(c1) &lt;&lt; 32) + c2; union { FileTimeT as_file_time; </pre> </description> <category>Ticket</category> </item> <item> <dc:creator>Claudio Bley</dc:creator> <pubDate>Wed, 27 May 2009 06:54:17 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/2809#comment:7 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/2809#comment:7</guid> <description> <p> Replying to <a class="ticket" href="https://svn.boost.org/trac10/ticket/2809#comment:6" title="Comment 6">christian.stimming@ibeo-as.com</a>: </p> <blockquote class="citation"> <p> As an alternative to the patch above, the change below would fix the warning as well. </p> </blockquote> <p> I can't confirm that your patch works. Contrary, I still get the warning as well as the exception. </p> <p> Regards, Claudio </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Andrey Semashev</dc:creator> <pubDate>Thu, 04 Jun 2009 10:07:44 GMT</pubDate> <title>status changed; resolution set https://svn.boost.org/trac10/ticket/2809#comment:8 https://svn.boost.org/trac10/ticket/2809#comment:8 <ul> <li><strong>status</strong> <span class="trac-field-old">new</span> → <span class="trac-field-new">closed</span> </li> <li><strong>resolution</strong> → <span class="trac-field-new">fixed</span> </li> </ul> <p> (In <a class="changeset" href="https://svn.boost.org/trac10/changeset/53622" title="Fixes #2809.">[53622]</a>) Fixes <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/2809" title="#2809: Bugs: [patch] Date Time exception with MinGW (closed: fixed)">#2809</a>. </p> Ticket Andrey Semashev Sat, 06 Jun 2009 11:24:11 GMT <link>https://svn.boost.org/trac10/ticket/2809#comment:9 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/2809#comment:9</guid> <description> <p> (In <a class="changeset" href="https://svn.boost.org/trac10/changeset/53677" title="Fixes #2809.">[53677]</a>) Fixes <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/2809" title="#2809: Bugs: [patch] Date Time exception with MinGW (closed: fixed)">#2809</a>. </p> </description> <category>Ticket</category> </item> </channel> </rss>