[numeric_cast] Warning with MSVC
I'm using boost::numeric_cast to convert the size of a wstring (presumably
a size_t) to an int.
const int size = boost::numeric_cast<int>(my_string.size());
MSVC still gives me a warning about possible loss of data:
c:\program files\boost\boost_1_38\boost\numeric\conversion\
cast.hpp(41) : warning C4267: 'argument' : conversion from 'size_t'
to 'unsigned int', possible loss of data
c:\users\awl03\documents\visual studio 2005\projects\swish_trunk
(padd)\swish\utils.hpp(91) : see reference to function template
instantiation 'Target boost::numeric_cast
Alexander Lamaison wrote: Sent: Thursday, July 16, 2009 6:09 AM
I'm using boost::numeric_cast to convert the size of a wstring (presumably a size_t) to an int.
const int size = boost::numeric_cast<int>(my_string.size());
MSVC still gives me a warning about possible loss of data:
c:\program files\boost\boost_1_38\boost\numeric\conversion\ cast.hpp(41) : warning C4267: 'argument' : conversion from 'size_t' to 'unsigned int', possible loss of data c:\users\awl03\documents\visual studio 2005\projects\swish_trunk (padd)\swish\utils.hpp(91) : see reference to function template instantiation 'Target boost::numeric_cast
(Source)' being compiled with [ Target=int, Source=__w64 unsigned int ] c:\users\awl03\documents\visual studio 2005\projects\swish_trunk (padd)\swish\utils.hpp(121) : see reference to function template instantiation 'std::basic_string<_Elem,_Traits,_Ax> swish::utils::ConvertString<`anonymous-namespace'::Narrow>(const std::basic_string ,std:: allocator<_Ty>> &)' being compiled with [ _Elem=char, _Traits=std::char_traits<char>, _Ax=std::allocator<char>, _Ty=wchar_t ] Unless I misunderstand, isn't the idea of numeric_cast that warnings aren't needed because the casts are checked for loss of data? Any advice is greatly appreaciated.
I am using the MSVC 8.0 compiler with Boost 1.38.0 on 32-bit Windows Vista.
Thanks.
Alex Lamaison
The issue is a compiler option called "detect 64-bit portability issues" or "/Wp64". As it is both non-standard and a rather brutal hack, there is probably no way for Boost to support it. I would recommend turning that option off.
On Thu, Jul 16, 2009 at 8:29 AM, Andrew
Holden
Alexander Lamaison wrote: Sent: Thursday, July 16, 2009 6:09 AM
I'm using boost::numeric_cast to convert the size of a wstring (presumably a size_t) to an int.
const int size = boost::numeric_cast<int>(my_string.size());
MSVC still gives me a warning about possible loss of data:
c:\program files\boost\boost_1_38\boost\numeric\conversion\ cast.hpp(41) : warning C4267: 'argument' : conversion from 'size_t' to 'unsigned int', possible loss of data c:\users\awl03\documents\visual studio 2005\projects\swish_trunk (padd)\swish\utils.hpp(91) : see reference to function template instantiation 'Target boost::numeric_cast
(Source)' being compiled with [ Target=int, Source=__w64 unsigned int ] c:\users\awl03\documents\visual studio 2005\projects\swish_trunk (padd)\swish\utils.hpp(121) : see reference to function template instantiation 'std::basic_string<_Elem,_Traits,_Ax> swish::utils::ConvertString<`anonymous-namespace'::Narrow>(const std::basic_string ,std:: allocator<_Ty>> &)' being compiled with [ _Elem=char, _Traits=std::char_traits<char>, _Ax=std::allocator<char>, _Ty=wchar_t ] Unless I misunderstand, isn't the idea of numeric_cast that warnings aren't needed because the casts are checked for loss of data? Any advice is greatly appreaciated.
I am using the MSVC 8.0 compiler with Boost 1.38.0 on 32-bit Windows Vista.
Thanks.
Alex Lamaison
The issue is a compiler option called "detect 64-bit portability issues" or "/Wp64". As it is both non-standard and a rather brutal hack, there is probably no way for Boost to support it.
I would recommend turning that option off.
For what it's worth, this compiler option is deprecated in recent versions of MSVC, so that adds one more to the list of reasons to disable the option.
On Thu, 16 Jul 2009 11:18:26 -0500, Zachary Turner wrote:
On Thu, Jul 16, 2009 at 8:29 AM, Andrew Holden
wrote: Alexander Lamaison wrote: Sent: Thursday, July 16, 2009 6:09 AM
MSVC still gives me a warning about possible loss of data:
c:\program files\boost\boost_1_38\boost\numeric\conversion\ cast.hpp(41) : warning C4267: 'argument' : conversion from 'size_t' to 'unsigned int', possible loss of data
The issue is a compiler option called "detect 64-bit portability issues" or "/Wp64". As it is both non-standard and a rather brutal hack, there is probably no way for Boost to support it.
I would recommend turning that option off.
For what it's worth, this compiler option is deprecated in recent versions of MSVC, so that adds one more to the list of reasons to disable the option.
Not the first time this flag has given me trouble. I one had "conversion from 'size_t' to 'size_t', possible loss of data". Mint. Turning it off immediately. Alex
participants (3)
-
Alexander Lamaison
-
Andrew Holden
-
Zachary Turner