Opened 10 years ago

Closed 5 years ago

#6898 closed Bugs (fixed)

Compiler warning when using boost::posix_time::from_ftime.

Reported by: oscar.lara@… Owned by: Andrey Semashev
Milestone: Boost 1.66.0 Component: date_time
Version: Boost 1.42.0 Severity: Cosmetic
Keywords: Cc:

Description (last modified by viboes)

VC2005 compiler reports a compilation warning when using from_time function.

1>c:\workspace\boost\boost\date_time\filetime_functions.hpp(146) : warning C4244: 'initializing' : conversion from 'boost::uint64_t' to 'boost::uint32_t', possible loss of data 1> c:\workspace\boost\boost\date_time\posix_time\conversion.hpp(81) : see reference to function template instantiation 'TimeT boost::date_time::time_from_ftime<TimeT,FileTimeT>(const FileTimeT &)' being compiled 1> with 1> [ 1> TimeT=boost::posix_time::ptime, 1> FileTimeT=FILETIME 1> ] 1> c:\workspace\blah\rainbowkeyimpl.cpp(126) : see reference to function template instantiation 'TimeT boost::posix_time::from_ftime<boost::posix_time::ptime,FILETIME>(const FileTimeT &)' being compiled 1> with 1> [ 1> TimeT=boost::posix_time::ptime, 1> FileTimeT=FILETIME 1> ]

Looking the code in the latest Boost version the line that the warning is pointing hasn't changed.

uint32_t sub_sec = (caster.as_integer % 10000000UL) 
#if !defined(BOOST_DATE_TIME_POSIX_TIME_STD_CONFIG)
        / 10; // microseconds since the last second
#else
        * 100; // nanoseconds since the last second
#endif

A quick way to resolve it would be to static_cast<uint32_t> the results. The cast shouldn't cause any data loss as the mod is and the multiplication are keeping the maximum value within the uint32_t range.

Change History (4)

comment:1 by anonymous, 10 years ago

Sorry my last sentence was meant to say: ...the mod and the multiplication are keeping

comment:2 by viboes, 10 years ago

Description: modified (diff)

comment:3 by James E. King, III, 5 years ago

Milestone: To Be DeterminedBoost 1.66.0
Owner: changed from az_sw_dude to Andrey Semashev

comment:4 by James E. King, III, 5 years ago

Resolution: fixed
Status: newclosed
Note: See TracTickets for help on using tickets.