Boost C++ Libraries: Ticket #2819: boost::posix_time::hours, minutes, and seconds assume sizeof(long) == sizeof(int) https://svn.boost.org/trac10/ticket/2819 <p> The constructors for boost::posix_time::hours, minutes, and seconds take arguments of type long, which is 64 bits on 64 bit LP64 environments like MacOS 10.5. This leads to warnings about possible truncation when these arguments are passed to the constructor for time_duration. Since time_duration is a template class that can be instantiated for different types, boost::sint32_t seems like a safer type to use in the non-templated constructors in boost::posix_time than a compiler-specific type like long. </p> <pre class="wiki"> //! Allows expression of durations as an hour count /*! \ingroup time_basics */ class hours : public time_duration { public: explicit hours(boost::int32_t h) : time_duration(h,0,0) {} }; //! Allows expression of durations as a minute count /*! \ingroup time_basics */ class minutes : public time_duration { public: explicit minutes(boost::int32_t m) : time_duration(0,m,0) {} }; //! Allows expression of durations as a seconds count /*! \ingroup time_basics */ class seconds : public time_duration { public: explicit seconds(boost::int32_t s) : time_duration(0,0,s) {} }; </pre> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/2819 Trac 1.4.3 pelee@… Tue, 03 Mar 2009 22:38:48 GMT <link>https://svn.boost.org/trac10/ticket/2819#comment:1 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/2819#comment:1</guid> <description> <p> Making this change also causes a 64-to-32 bit warning in xtime. The solution is to update a call to posix_time::seconds() to cast its argument to boost::int32_t instead of long. </p> <pre class="wiki"> operator system_time() const { return boost::posix_time::from_time_t(0)+ boost::posix_time::seconds(static_cast&lt;boost::int32_t&gt;(sec))+ #ifdef BOOST_DATE_TIME_HAS_NANOSECONDS boost::posix_time::nanoseconds(nsec); #else boost::posix_time::microseconds((nsec+500)/1000); #endif } </pre> </description> <category>Ticket</category> </item> <item> <author>robert.stewart@…</author> <pubDate>Thu, 13 Aug 2009 14:03:36 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/2819#comment:2 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/2819#comment:2</guid> <description> <p> These same warnings occur for GCC 4.3.2 on 64b Linux. </p> <p> Just casting to a smaller type is suspect as the caller can supply a value in the range of the larger type that overflows the smaller. The cast is acceptable if the range is checked, but it may be better to try to bring greater consistency to the integer types being used. </p> </description> <category>Ticket</category> </item> <item> <author>Rob Stewart <robert.stewart@…></author> <pubDate>Thu, 29 Jul 2010 17:32:02 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/2819#comment:3 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/2819#comment:3</guid> <description> <p> I just ran afoul of this impedance mismatch yet again. The value fit long, but not int, the underlying type of time_duration::sec_type in this case. The truncation caused a large negative value to be treated as a sizable positive value silently creating a future rather than past time. </p> <p> I think the proper solution is to change the classes to use the typedefs from the base class, giving the following: </p> <pre class="wiki"> class hours : public time_duration { public: explicit hours(hour_type h) : time_duration(h,0,0) {} }; class minutes : public time_duration { public: explicit minutes(min_type m) : time_duration(0,m,0) {} }; class seconds : public time_duration { public: explicit seconds(sec_type s) : time_duration(0,0,s) {} }; </pre><p> Ensuring values fit within those types then becomes the caller's responsibility; DateTime won't silently truncate or otherwise alter them. </p> </description> <category>Ticket</category> </item> <item> <author>pankajuj@…</author> <pubDate>Wed, 21 Dec 2011 04:37:16 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/2819#comment:4 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/2819#comment:4</guid> <description> <p> Has anyone found a good fix for this issue? It looks like using the library for a 64 bit linux or mac platforms is not safe. Will the future version of boost have the fix? </p> </description> <category>Ticket</category> </item> <item> <dc:creator>James E. King, III</dc:creator> <pubDate>Thu, 18 Jan 2018 14:18:08 GMT</pubDate> <title>owner, version, milestone changed https://svn.boost.org/trac10/ticket/2819#comment:5 https://svn.boost.org/trac10/ticket/2819#comment:5 <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>version</strong> <span class="trac-field-old">Boost Release Branch</span> → <span class="trac-field-new">Boost 1.37.0</span> </li> <li><strong>milestone</strong> <span class="trac-field-old">Boost 1.39.0</span> → <span class="trac-field-new">Boost 1.67.0</span> </li> </ul> <p> Resolved as part of github issue 56: </p> <p> <a class="ext-link" href="https://github.com/boostorg/date_time/commit/de171954fe45e4d1338a641ebe70a84a181bd258#diff-c68588b074fe6450f9ed1dedc759621eR94"><span class="icon">​</span>https://github.com/boostorg/date_time/commit/de171954fe45e4d1338a641ebe70a84a181bd258#diff-c68588b074fe6450f9ed1dedc759621eR94</a> </p> Ticket James E. King, III Sun, 28 Jan 2018 16:22:55 GMT status changed; resolution set https://svn.boost.org/trac10/ticket/2819#comment:6 https://svn.boost.org/trac10/ticket/2819#comment:6 <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> Fix merged to master; resolved. </p> Ticket