Boost C++ Libraries: Ticket #2801: gregorian_calendar_base: incorrectly assumes that sizeof(int)==sizeof(long) https://svn.boost.org/trac10/ticket/2801 <p> boost::date_time::gregorian_calendar_base() returns an int, but uses several local variables of type unsigned long, leading to warnings about possible loss of data when converting from unsigned long to int on 64 bit OSes that use the LP64 data model. </p> <p> Here is a rewrite of the function that generates no warnings when compiled with -Wshorten-64-to-32 under GCC 4.0.1 on Mac OS 10.5: </p> <pre class="wiki"> template&lt;typename ymd_type_, typename date_int_type_&gt; BOOST_DATE_TIME_INLINE int gregorian_calendar_base&lt;ymd_type_,date_int_type_&gt;::week_number(const ymd_type&amp; ymd) { date_int_type_ julianbegin = julian_day_number(ymd_type(ymd.year,1,1)); date_int_type_ juliantoday = julian_day_number(ymd); date_int_type_ day = (julianbegin + 3) % 7; date_int_type_ week = (juliantoday + day - julianbegin + 4)/7; if ((week &gt;= 1) &amp;&amp; (week &lt;= 52)) { return static_cast&lt;int&gt;(week); } if ((week == 53)) { if((day==6) ||(day == 5 &amp;&amp; is_leap_year(ymd.year))) { return static_cast&lt;int&gt;(week); //under these circumstances week == 53. } else { return 1; //monday - wednesday is in week 1 of next year } } //if the week is not in current year recalculate using the previous year as the beginning year else if (week == 0) { julianbegin = julian_day_number(ymd_type(static_cast&lt;unsigned short&gt;(ymd.year-1),1,1)); juliantoday = julian_day_number(ymd); day = (julianbegin + 3) % 7; week = (juliantoday + day - julianbegin + 4)/7; return static_cast&lt;int&gt;(week); } return static_cast&lt;int&gt;(week); //not reachable -- well except if day == 5 and is_leap_year != true } </pre> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/2801 Trac 1.4.3 Ben Craig <ben.craig@…> Mon, 08 Oct 2012 19:57:03 GMT <link>https://svn.boost.org/trac10/ticket/2801#comment:1 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/2801#comment:1</guid> <description> <p> This is causing a ton of warnings for my builds of Apache Thrift. Apache Thrift doesn't directly use date_time, but it does use thread. Boost 1.50's thread library pulls in date_time. </p> <p> I am also affected by <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/2818" title="#2818: Bugs: boost::posix_time::from_time_t() assumes boost::int32_t == long (closed: fixed)">#2818</a> and <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/2819" title="#2819: Bugs: boost::posix_time::hours, minutes, and seconds assume sizeof(long) == ... (closed: fixed)">#2819</a>. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>James E. King, III</dc:creator> <pubDate>Thu, 18 Jan 2018 14:19:55 GMT</pubDate> <title>owner, status, version, milestone changed https://svn.boost.org/trac10/ticket/2801#comment:2 https://svn.boost.org/trac10/ticket/2801#comment:2 <ul> <li><strong>owner</strong> changed from <span class="trac-author">az_sw_dude</span> to <span class="trac-author">James E. King, III</span> </li> <li><strong>status</strong> <span class="trac-field-old">new</span> → <span class="trac-field-new">assigned</span> </li> <li><strong>version</strong> <span class="trac-field-old">Boost Release Branch</span> → <span class="trac-field-new">Boost 1.38.0</span> </li> <li><strong>milestone</strong> <span class="trac-field-old">Boost 1.39.0</span> → <span class="trac-field-new">To Be Determined</span> </li> </ul> Ticket