Boost C++ Libraries: Ticket #7687: [date_time] implicit conversion loses integer precision https://svn.boost.org/trac10/ticket/7687 <p> Compiling with Apple/clang-421.11.66, including boost/date_time.hpp, gives multiple warnings about implicite long64 to int32 conversions: </p> <p> main.cpp:9 </p> <pre class="wiki">#include &lt;boost/date_time.hpp&gt; </pre><pre class="wiki">clang -x c++ -stdlib=libstdc++ -Iboost_1_52_0 -Wshorten-64-to-32 -c main.cpp In file included from main.cpp:9: In file included from boost_1_52_0/boost/date_time.hpp:15: In file included from boost_1_52_0/boost/date_time/local_time/local_time.hpp:11: In file included from boost_1_52_0/boost/date_time/posix_time/posix_time.hpp:24: In file included from boost_1_52_0/boost/date_time/posix_time/time_formatters.hpp:16: In file included from boost_1_52_0/boost/date_time/posix_time/posix_time_types.hpp:16: boost_1_52_0/boost/date_time/posix_time/posix_time_duration.hpp:24:21: warning: implicit conversion loses integer precision: 'long' to 'hour_type' (aka 'int') [-Wshorten-64-to-32] time_duration(h,0,0) ~~~~~~~~~~~~~ ^ boost_1_52_0/boost/date_time/posix_time/posix_time_duration.hpp:35:23: warning: implicit conversion loses integer precision: 'long' to 'min_type' (aka 'int') [-Wshorten-64-to-32] time_duration(0,m,0) ~~~~~~~~~~~~~ ^ boost_1_52_0/boost/date_time/posix_time/posix_time_duration.hpp:46:25: warning: implicit conversion loses integer precision: 'long' to 'sec_type' (aka 'int') [-Wshorten-64-to-32] time_duration(0,0,s) ~~~~~~~~~~~~~ ^ In file included from main.cpp:9: In file included from boost_1_52_0/boost/date_time.hpp:15: In file included from boost_1_52_0/boost/date_time/local_time/local_time.hpp:11: In file included from boost_1_52_0/boost/date_time/posix_time/posix_time.hpp:15: In file included from boost_1_52_0/boost/date_time/posix_time/ptime.hpp:12: In file included from boost_1_52_0/boost/date_time/posix_time/posix_time_system.hpp:13: In file included from boost_1_52_0/boost/date_time/posix_time/posix_time_config.hpp:18: In file included from boost_1_52_0/boost/date_time/gregorian/gregorian_types.hpp:19: In file included from boost_1_52_0/boost/date_time/gregorian/greg_calendar.hpp:15: In file included from boost_1_52_0/boost/date_time/gregorian_calendar.hpp:63: boost_1_52_0/boost/date_time/gregorian_calendar.ipp:82:12: warning: implicit conversion loses integer precision: 'unsigned long' to 'date_int_type' (aka 'unsigned int') [-Wshorten-64-to-32] return d; ~~~~~~ ^ boost_1_52_0/boost/date_time/date.hpp:71:25: note: in instantiation of member function 'boost::date_time::gregorian_calendar_base&lt;boost::date_time::year_month_day_base&lt;boost::gregorian::greg_year, boost::gregorian::greg_month, boost::gregorian::greg_day&gt;, unsigned int&gt;::day_number' requested here : days_(calendar::day_number(ymd_type(y, m, d))) ^ boost_1_52_0/boost/date_time/gregorian/greg_date.hpp:56:9: note: in instantiation of member function 'boost::date_time::date&lt;boost::gregorian::date, boost::gregorian::gregorian_calendar, boost::gregorian::date_duration&gt;::date' requested here : date_time::date&lt;date, gregorian_calendar, date_duration&gt;(y, m, d) ^ In file included from main.cpp:9: In file included from boost_1_52_0/boost/date_time.hpp:15: In file included from boost_1_52_0/boost/date_time/local_time/local_time.hpp:11: In file included from boost_1_52_0/boost/date_time/posix_time/posix_time.hpp:15: In file included from boost_1_52_0/boost/date_time/posix_time/ptime.hpp:12: In file included from boost_1_52_0/boost/date_time/posix_time/posix_time_system.hpp:13: In file included from boost_1_52_0/boost/date_time/posix_time/posix_time_config.hpp:18: In file included from boost_1_52_0/boost/date_time/gregorian/gregorian_types.hpp:19: In file included from boost_1_52_0/boost/date_time/gregorian/greg_calendar.hpp:15: In file included from boost_1_52_0/boost/date_time/gregorian_calendar.hpp:63: boost_1_52_0/boost/date_time/gregorian_calendar.ipp:47:14: warning: implicit conversion loses integer precision: 'unsigned long' to 'int' [-Wshorten-64-to-32] return week; ~~~~~~ ^~~~ boost_1_52_0/boost/date_time/gregorian/greg_date.hpp:111:34: note: in instantiation of member function 'boost::date_time::gregorian_calendar_base&lt;boost::date_time::year_month_day_base&lt;boost::gregorian::greg_year, boost::gregorian::greg_month, boost::gregorian::greg_day&gt;, unsigned int&gt;::week_number' requested here return gregorian_calendar::week_number(ymd); ^ In file included from main.cpp:9: In file included from boost_1_52_0/boost/date_time.hpp:15: In file included from boost_1_52_0/boost/date_time/local_time/local_time.hpp:11: In file included from boost_1_52_0/boost/date_time/posix_time/posix_time.hpp:15: In file included from boost_1_52_0/boost/date_time/posix_time/ptime.hpp:12: In file included from boost_1_52_0/boost/date_time/posix_time/posix_time_system.hpp:13: In file included from boost_1_52_0/boost/date_time/posix_time/posix_time_config.hpp:18: In file included from boost_1_52_0/boost/date_time/gregorian/gregorian_types.hpp:19: In file included from boost_1_52_0/boost/date_time/gregorian/greg_calendar.hpp:15: In file included from boost_1_52_0/boost/date_time/gregorian_calendar.hpp:63: boost_1_52_0/boost/date_time/gregorian_calendar.ipp:52:16: warning: implicit conversion loses integer precision: 'unsigned long' to 'int' [-Wshorten-64-to-32] return week; //under these circumstances week == 53. ~~~~~~ ^~~~ boost_1_52_0/boost/date_time/gregorian_calendar.ipp:63:14: warning: implicit conversion loses integer precision: 'unsigned long' to 'int' [-Wshorten-64-to-32] return week; ~~~~~~ ^~~~ boost_1_52_0/boost/date_time/gregorian_calendar.ipp:66:12: warning: implicit conversion loses integer precision: 'unsigned long' to 'int' [-Wshorten-64-to-32] return week; //not reachable -- well except if day == 5 and is_leap_year != true ~~~~~~ ^~~~ In file included from main.cpp:9: In file included from boost_1_52_0/boost/date_time.hpp:15: In file included from boost_1_52_0/boost/date_time/local_time/local_time.hpp:11: In file included from boost_1_52_0/boost/date_time/posix_time/posix_time.hpp:15: In file included from boost_1_52_0/boost/date_time/posix_time/ptime.hpp:12: In file included from boost_1_52_0/boost/date_time/posix_time/posix_time_system.hpp:15: boost_1_52_0/boost/date_time/time_system_counted.hpp:57:52: warning: implicit conversion loses integer precision: 'unsigned long' to 'typename calendar_type::date_int_type' (aka 'unsigned int') [-Wshorten-64-to-32] typename calendar_type::date_int_type dc = day_count(); ~~ ^~~~~~~~~~~ boost_1_52_0/boost/date_time/time_system_counted.hpp:170:18: note: in instantiation of member function 'boost::date_time::counted_time_rep&lt;boost::posix_time::millisec_posix_time_system_config&gt;::date' requested here return val.date(); ^ boost_1_52_0/boost/date_time/time.hpp:72:27: note: in instantiation of member function 'boost::date_time::counted_time_system&lt;boost::date_time::counted_time_rep&lt;boost::posix_time::millisec_posix_time_system_config&gt; &gt;::get_date' requested here return time_system::get_date(time_); ^ boost_1_52_0/boost/date_time/posix_time/date_duration_operators.hpp:33:31: note: in instantiation of member function 'boost::date_time::base_time&lt;boost::posix_time::ptime, boost::date_time::counted_time_system&lt;boost::date_time::counted_time_rep&lt;boost::posix_time::millisec_posix_time_system_config&gt;&gt; &gt;::date' requested here return t + m.get_offset(t.date()); ^ In file included from main.cpp:9: In file included from boost_1_52_0/boost/date_time.hpp:15: In file included from boost_1_52_0/boost/date_time/local_time/local_time.hpp:11: In file included from boost_1_52_0/boost/date_time/posix_time/posix_time.hpp:15: In file included from boost_1_52_0/boost/date_time/posix_time/ptime.hpp:12: In file included from boost_1_52_0/boost/date_time/posix_time/posix_time_system.hpp:13: In file included from boost_1_52_0/boost/date_time/posix_time/posix_time_config.hpp:18: In file included from boost_1_52_0/boost/date_time/gregorian/gregorian_types.hpp:17: boost_1_52_0/boost/date_time/date.hpp:180:47: warning: implicit conversion loses integer precision: 'duration_rep_type' (aka 'long') to 'int_type' (aka 'unsigned int') [-Wshorten-64-to-32] return date_type(date_rep_type(days_) + dd.days()); ~~~~~~~~~~~~~ ^~~~~~~~~ boost_1_52_0/boost/date_time/time.hpp:145:49: note: in instantiation of member function 'boost::date_time::date&lt;boost::gregorian::date, boost::gregorian::gregorian_calendar, boost::gregorian::date_duration&gt;::operator+' requested here time_ = (time_system::get_time_rep(date() + dd, time_of_day())); ^ boost_1_52_0/boost/date_time/posix_time/date_duration_operators.hpp:44:14: note: in instantiation of member function 'boost::date_time::base_time&lt;boost::posix_time::ptime, boost::date_time::counted_time_system&lt;boost::date_time::counted_time_rep&lt;boost::posix_time::millisec_posix_time_system_config&gt;&gt; &gt;::operator+=' requested here return t += m.get_offset(t.date()); ^ In file included from main.cpp:9: In file included from boost_1_52_0/boost/date_time.hpp:15: In file included from boost_1_52_0/boost/date_time/local_time/local_time.hpp:11: In file included from boost_1_52_0/boost/date_time/posix_time/posix_time.hpp:15: In file included from boost_1_52_0/boost/date_time/posix_time/ptime.hpp:12: In file included from boost_1_52_0/boost/date_time/posix_time/posix_time_system.hpp:13: In file included from boost_1_52_0/boost/date_time/posix_time/posix_time_config.hpp:17: In file included from boost_1_52_0/boost/date_time/time_resolution_traits.hpp:15: boost_1_52_0/boost/date_time/int_adapter.hpp:233:41: warning: implicit conversion loses integer precision: 'long' to 'int_type' (aka 'unsigned int') [-Wshorten-64-to-32] return int_adapter&lt;int_type&gt;(value_ + rhs.as_number()); ~~~~~~~~~~~ ~~~~~~~^~~~~~~~~~~~~~~~~ boost_1_52_0/boost/date_time/date.hpp:178:47: note: in instantiation of function template specialization 'boost::date_time::int_adapter&lt;unsigned int&gt;::operator+&lt;long&gt;' requested here return date_type(date_rep_type(days_) + dd.get_rep()); ^ boost_1_52_0/boost/date_time/time.hpp:145:49: note: in instantiation of member function 'boost::date_time::date&lt;boost::gregorian::date, boost::gregorian::gregorian_calendar, boost::gregorian::date_duration&gt;::operator+' requested here time_ = (time_system::get_time_rep(date() + dd, time_of_day())); ^ boost_1_52_0/boost/date_time/posix_time/date_duration_operators.hpp:44:14: note: in instantiation of member function 'boost::date_time::base_time&lt;boost::posix_time::ptime, boost::date_time::counted_time_system&lt;boost::date_time::counted_time_rep&lt;boost::posix_time::millisec_posix_time_system_config&gt;&gt; &gt;::operator+=' requested here return t += m.get_offset(t.date()); ^ In file included from main.cpp:9: In file included from boost_1_52_0/boost/date_time.hpp:15: In file included from boost_1_52_0/boost/date_time/local_time/local_time.hpp:11: In file included from boost_1_52_0/boost/date_time/posix_time/posix_time.hpp:15: In file included from boost_1_52_0/boost/date_time/posix_time/ptime.hpp:12: In file included from boost_1_52_0/boost/date_time/posix_time/posix_time_system.hpp:13: In file included from boost_1_52_0/boost/date_time/posix_time/posix_time_config.hpp:18: In file included from boost_1_52_0/boost/date_time/gregorian/gregorian_types.hpp:17: boost_1_52_0/boost/date_time/date.hpp:162:47: warning: implicit conversion loses integer precision: 'duration_rep_type' (aka 'long') to 'int_type' (aka 'unsigned int') [-Wshorten-64-to-32] return date_type(date_rep_type(days_) - dd.days()); ~~~~~~~~~~~~~ ^~~~~~~~~ boost_1_52_0/boost/date_time/period.hpp:93:21: note: in instantiation of member function 'boost::date_time::date&lt;boost::gregorian::date, boost::gregorian::gregorian_calendar, boost::gregorian::date_duration&gt;::operator-' requested here last_(end_point - duration_rep::unit()) ^ boost_1_52_0/boost/date_time/date_parsing.hpp:308:14: note: in instantiation of member function 'boost::date_time::period&lt;boost::gregorian::date, boost::gregorian::date_duration&gt;::period' requested here return period&lt;date_type, typename date_type::duration_type&gt;(d1, d2); ^ boost_1_52_0/boost/date_time/gregorian/parsers.hpp:79:12: note: in instantiation of function template specialization 'boost::date_time::from_simple_string_type&lt;boost::gregorian::date, char&gt;' requested here return date_time::from_simple_string_type&lt;date,char&gt;(s); ^ In file included from main.cpp:9: In file included from boost_1_52_0/boost/date_time.hpp:15: In file included from boost_1_52_0/boost/date_time/local_time/local_time.hpp:11: In file included from boost_1_52_0/boost/date_time/posix_time/posix_time.hpp:15: In file included from boost_1_52_0/boost/date_time/posix_time/ptime.hpp:12: In file included from boost_1_52_0/boost/date_time/posix_time/posix_time_system.hpp:13: In file included from boost_1_52_0/boost/date_time/posix_time/posix_time_config.hpp:17: In file included from boost_1_52_0/boost/date_time/time_resolution_traits.hpp:15: boost_1_52_0/boost/date_time/int_adapter.hpp:282:41: warning: implicit conversion loses integer precision: 'long' to 'int_type' (aka 'unsigned int') [-Wshorten-64-to-32] return int_adapter&lt;int_type&gt;(value_ - rhs.as_number()); ~~~~~~~~~~~ ~~~~~~~^~~~~~~~~~~~~~~~~ boost_1_52_0/boost/date_time/date.hpp:160:47: note: in instantiation of function template specialization 'boost::date_time::int_adapter&lt;unsigned int&gt;::operator-&lt;long&gt;' requested here return date_type(date_rep_type(days_) - dd.get_rep()); ^ boost_1_52_0/boost/date_time/period.hpp:93:21: note: in instantiation of member function 'boost::date_time::date&lt;boost::gregorian::date, boost::gregorian::gregorian_calendar, boost::gregorian::date_duration&gt;::operator-' requested here last_(end_point - duration_rep::unit()) ^ boost_1_52_0/boost/date_time/date_parsing.hpp:308:14: note: in instantiation of member function 'boost::date_time::period&lt;boost::gregorian::date, boost::gregorian::date_duration&gt;::period' requested here return period&lt;date_type, typename date_type::duration_type&gt;(d1, d2); ^ boost_1_52_0/boost/date_time/gregorian/parsers.hpp:79:12: note: in instantiation of function template specialization 'boost::date_time::from_simple_string_type&lt;boost::gregorian::date, char&gt;' requested here return date_time::from_simple_string_type&lt;date,char&gt;(s); ^ In file included from main.cpp:9: In file included from boost_1_52_0/boost/date_time.hpp:15: In file included from boost_1_52_0/boost/date_time/local_time/local_time.hpp:11: In file included from boost_1_52_0/boost/date_time/posix_time/posix_time.hpp:24: In file included from boost_1_52_0/boost/date_time/posix_time/time_formatters.hpp:16: In file included from boost_1_52_0/boost/date_time/posix_time/posix_time_types.hpp:20: boost_1_52_0/boost/date_time/dst_rules.hpp:57:49: warning: implicit conversion loses integer precision: 'long' to 'min_type' (aka 'int') [-Wshorten-64-to-32] if (time_of_day &gt;= time_duration_type(0,offset,0)) { ~~~~~~~~~~~~~~~~~~ ^~~~~~ boost_1_52_0/boost/date_time/dst_rules.hpp:164:18: note: in instantiation of member function 'boost::date_time::dst_calculator&lt;boost::gregorian::date, boost::posix_time::time_duration&gt;::process_local_dst_start_day' requested here return process_local_dst_start_day(time_of_day, ^ boost_1_52_0/boost/date_time/dst_rules.hpp:116:16: note: in instantiation of member function 'boost::date_time::dst_calculator&lt;boost::gregorian::date, boost::posix_time::time_duration&gt;::local_is_dst' requested here return local_is_dst(current_day, time_of_day, ^ boost_1_52_0/boost/date_time/local_time/local_date_time.hpp:196:16: note: in instantiation of member function 'boost::date_time::dst_calculator&lt;boost::gregorian::date, boost::posix_time::time_duration&gt;::local_is_dst' requested here return dst_calculator::local_is_dst( ^ boost_1_52_0/boost/date_time/local_time/local_date_time.hpp:241:16: note: in instantiation of member function 'boost::local_time::local_date_time_base&lt;boost::posix_time::ptime, boost::date_time::time_zone_base&lt;boost::posix_time::ptime, char&gt; &gt;::check_dst' requested here switch(check_dst(lt.date(), lt.time_of_day(), zone_)){ ^ boost_1_52_0/boost/date_time/local_time/conversion.hpp:23:9: note: in instantiation of member function 'boost::local_time::local_date_time_base&lt;boost::posix_time::ptime, boost::date_time::time_zone_base&lt;boost::posix_time::ptime, char&gt; &gt;::is_dst' requested here if(lt.is_dst()){ ^ In file included from main.cpp:9: In file included from boost_1_52_0/boost/date_time.hpp:15: In file included from boost_1_52_0/boost/date_time/local_time/local_time.hpp:11: In file included from boost_1_52_0/boost/date_time/posix_time/posix_time.hpp:24: In file included from boost_1_52_0/boost/date_time/posix_time/time_formatters.hpp:16: In file included from boost_1_52_0/boost/date_time/posix_time/posix_time_types.hpp:20: boost_1_52_0/boost/date_time/dst_rules.hpp:78:44: warning: implicit conversion loses integer precision: 'long' to 'int' [-Wshorten-64-to-32] int offset = dst_end_offset_minutes-dst_length_minutes; ~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~ boost_1_52_0/boost/date_time/dst_rules.hpp:170:18: note: in instantiation of member function 'boost::date_time::dst_calculator&lt;boost::gregorian::date, boost::posix_time::time_duration&gt;::process_local_dst_end_day' requested here return process_local_dst_end_day(time_of_day, ^ boost_1_52_0/boost/date_time/dst_rules.hpp:116:16: note: in instantiation of member function 'boost::date_time::dst_calculator&lt;boost::gregorian::date, boost::posix_time::time_duration&gt;::local_is_dst' requested here return local_is_dst(current_day, time_of_day, ^ boost_1_52_0/boost/date_time/local_time/local_date_time.hpp:196:16: note: in instantiation of member function 'boost::date_time::dst_calculator&lt;boost::gregorian::date, boost::posix_time::time_duration&gt;::local_is_dst' requested here return dst_calculator::local_is_dst( ^ boost_1_52_0/boost/date_time/local_time/local_date_time.hpp:241:16: note: in instantiation of member function 'boost::local_time::local_date_time_base&lt;boost::posix_time::ptime, boost::date_time::time_zone_base&lt;boost::posix_time::ptime, char&gt; &gt;::check_dst' requested here switch(check_dst(lt.date(), lt.time_of_day(), zone_)){ ^ boost_1_52_0/boost/date_time/local_time/conversion.hpp:23:9: note: in instantiation of member function 'boost::local_time::local_date_time_base&lt;boost::posix_time::ptime, boost::date_time::time_zone_base&lt;boost::posix_time::ptime, char&gt; &gt;::is_dst' requested here if(lt.is_dst()){ ^ 15 warnings generated. </pre> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/7687 Trac 1.4.3 matt@… Mon, 11 Feb 2013 01:20:28 GMT <link>https://svn.boost.org/trac10/ticket/7687#comment:1 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/7687#comment:1</guid> <description> <p> I just wanted to clarify the cause of the bug here: </p> <p> posix_time exposes classes (hours, minutes, seconds) that take a "long" as their constructor. These parameters are passed through to the internal time_resolution_traits and stored in a "v_type" which is int32_t in the default template parameter construction. </p> <p> On LP64 platforms (64-bit except Windows), long and int32_t are not the same size. The time_resolution_traits default type for "v_type" should probably be upgraded to use a "long" since this could be done without changing the external interface to posix_time. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>anonymous</dc:creator> <pubDate>Tue, 01 Dec 2015 09:11:50 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/7687#comment:2 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/7687#comment:2</guid> <description> <p> Still the same in 1.58 and XCode 6.4. Annoying warning this one. </p> </description> <category>Ticket</category> </item> </channel> </rss>