Boost C++ Libraries: Ticket #5614: date bug in release (boost 1.46) https://svn.boost.org/trac10/ticket/5614 <p> The bug is present only in Release (WinXP + Boost 1.46) not in Debug. </p> <p> The bug is produced as follows: </p> <pre class="wiki">#include "boost/date_time/gregorian/gregorian.hpp" using namespace boost::gregorian; void func() { date todaysdate(day_clock::local_day()); printf("%i-%02i-%02i\n",todaysdate.year(), todaysdate.month(), todaysdate.day()); } </pre><p> This prints gibberish values or more precisely, the lowest 16 bits are correct but the highest 16 bits contain random data. </p> <p> The date itself seems to work perfectly well, I can compare dates, increment and so on, it is only the year(), month() etc. functions that seems broken. </p> <p> HTH &amp; keep up the good work!! </p> <p> Valmond </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/5614 Trac 1.4.3 anonymous Thu, 16 Jun 2011 14:37:42 GMT component changed; owner set https://svn.boost.org/trac10/ticket/5614#comment:1 https://svn.boost.org/trac10/ticket/5614#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 Andrey Semashev Wed, 12 Mar 2014 17:13:03 GMT status changed; resolution set https://svn.boost.org/trac10/ticket/5614#comment:2 https://svn.boost.org/trac10/ticket/5614#comment:2 <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">invalid</span> </li> </ul> <p> Your use of printf is incorrect. year(), month() and day() methods return class types which have conversion operators to unsigned short. This results in incorrect arguments being passed to printf, which makes the output incorrect. </p> <p> A good compiler would warn you about such inconsistency, and gcc 4.8 actually does that: </p> <pre class="wiki">ymd_test.cpp:14:81: warning: format ‘%i’ expects argument of type ‘int’, but argument 2 has type ‘boost::date_time::date&lt;boost::gregorian::date, boost::gregorian::gregorian_calendar, boost::gregorian::date_duration&gt;::year_type {aka boost::gregorian::greg_year}’ [-Wformat=] printf("%i-%02i-%02i\n",todaysdate.year(), todaysdate.month(), todaysdate.day()); ^ ymd_test.cpp:14:81: warning: format ‘%i’ expects argument of type ‘int’, but argument 3 has type ‘boost::date_time::date&lt;boost::gregorian::date, boost::gregorian::gregorian_calendar, boost::gregorian::date_duration&gt;::month_type {aka boost::gregorian::greg_month}’ [-Wformat=] ymd_test.cpp:14:81: warning: format ‘%i’ expects argument of type ‘int’, but argument 4 has type ‘boost::date_time::date&lt;boost::gregorian::date, boost::gregorian::gregorian_calendar, boost::gregorian::date_duration&gt;::day_type {aka boost::gregorian::greg_day}’ [-Wformat=] }}} </pre> Ticket anonymous Sun, 30 Mar 2014 14:58:21 GMT <link>https://svn.boost.org/trac10/ticket/5614#comment:3 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/5614#comment:3</guid> <description> <p> Except that neither Qt nor MSVC 2010 detects this. </p> <p> The solution would have been to always truncate the numbers but, hey, no problem. On the other hand, few people uses Boost any more (it's all in 0x11 now) for new projects and as this ticket have been open for years, older projects will have done workarounds and as I said, it doesn't impact new projects. </p> <p> Cheers </p> </description> <category>Ticket</category> </item> </channel> </rss>