Opened 10 years ago
Last modified 7 years ago
#7687 new Bugs
[date_time] implicit conversion loses integer precision
Reported by: | Owned by: | az_sw_dude | |
---|---|---|---|
Milestone: | To Be Determined | Component: | date_time |
Version: | Boost 1.52.0 | Severity: | Cosmetic |
Keywords: | Cc: |
Description
Compiling with Apple/clang-421.11.66, including boost/date_time.hpp, gives multiple warnings about implicite long64 to int32 conversions:
main.cpp:9
#include <boost/date_time.hpp>
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<boost::date_time::year_month_day_base<boost::gregorian::greg_year, boost::gregorian::greg_month, boost::gregorian::greg_day>, unsigned int>::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<boost::gregorian::date, boost::gregorian::gregorian_calendar, boost::gregorian::date_duration>::date' requested here : date_time::date<date, gregorian_calendar, date_duration>(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<boost::date_time::year_month_day_base<boost::gregorian::greg_year, boost::gregorian::greg_month, boost::gregorian::greg_day>, unsigned int>::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<boost::posix_time::millisec_posix_time_system_config>::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<boost::date_time::counted_time_rep<boost::posix_time::millisec_posix_time_system_config> >::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<boost::posix_time::ptime, boost::date_time::counted_time_system<boost::date_time::counted_time_rep<boost::posix_time::millisec_posix_time_system_config>> >::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<boost::gregorian::date, boost::gregorian::gregorian_calendar, boost::gregorian::date_duration>::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<boost::posix_time::ptime, boost::date_time::counted_time_system<boost::date_time::counted_time_rep<boost::posix_time::millisec_posix_time_system_config>> >::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<int_type>(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<unsigned int>::operator+<long>' 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<boost::gregorian::date, boost::gregorian::gregorian_calendar, boost::gregorian::date_duration>::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<boost::posix_time::ptime, boost::date_time::counted_time_system<boost::date_time::counted_time_rep<boost::posix_time::millisec_posix_time_system_config>> >::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<boost::gregorian::date, boost::gregorian::gregorian_calendar, boost::gregorian::date_duration>::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<boost::gregorian::date, boost::gregorian::date_duration>::period' requested here return period<date_type, typename date_type::duration_type>(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<boost::gregorian::date, char>' requested here return date_time::from_simple_string_type<date,char>(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<int_type>(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<unsigned int>::operator-<long>' 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<boost::gregorian::date, boost::gregorian::gregorian_calendar, boost::gregorian::date_duration>::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<boost::gregorian::date, boost::gregorian::date_duration>::period' requested here return period<date_type, typename date_type::duration_type>(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<boost::gregorian::date, char>' requested here return date_time::from_simple_string_type<date,char>(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 >= 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<boost::gregorian::date, boost::posix_time::time_duration>::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<boost::gregorian::date, boost::posix_time::time_duration>::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<boost::gregorian::date, boost::posix_time::time_duration>::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<boost::posix_time::ptime, boost::date_time::time_zone_base<boost::posix_time::ptime, char> >::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<boost::posix_time::ptime, boost::date_time::time_zone_base<boost::posix_time::ptime, char> >::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<boost::gregorian::date, boost::posix_time::time_duration>::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<boost::gregorian::date, boost::posix_time::time_duration>::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<boost::gregorian::date, boost::posix_time::time_duration>::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<boost::posix_time::ptime, boost::date_time::time_zone_base<boost::posix_time::ptime, char> >::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<boost::posix_time::ptime, boost::date_time::time_zone_base<boost::posix_time::ptime, char> >::is_dst' requested here if(lt.is_dst()){ ^ 15 warnings generated.
Note:
See TracTickets
for help on using tickets.
I just wanted to clarify the cause of the bug here:
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.
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.