|
Boost Users : |
Subject: [Boost-users] [numeric_cast] Warning with MSVC
From: Alexander Lamaison (awl03_at_[hidden])
Date: 2009-07-16 06:09:20
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<int,__w64 unsigned
int>(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<wchar_t,std::char_traits<wchar_t>,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
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net