Boost logo

Boost :

Subject: Re: [boost] [units] gcc warnings
From: Emil Dotchevski (emil_at_[hidden])
Date: 2010-06-15 12:36:39


On Tue, Jun 15, 2010 at 4:56 AM, Jeff Flinn
<TriumphSprint2000_at_[hidden]> wrote:
> Stewart, Robert wrote:
>>
>> Jürgen Hunold wrote:
>>>
>>> I start using Boost.Units for a new project and found some
>>> annyoing warnings when compiling with "-Wall -Wextra" and
>>> "-Wconversion"
>>
>> Don't do that and you won't get those warnings!  (Just kidding.)
>>
>>> /home/hunold/src/devel/boost/boost/units/io.hpp: In function 'int
>>> boost::units::get_flags(std::ios_base&, int)':
>>> /home/hunold/src/devel/boost/boost/units/io.hpp:163: warning:
>>> conversion to
>>> 'int' from 'long int' may alter its value [-Wconversion]
>>>
>>> Patch using an explicit static_cast<int> for the return value
>>> attached.
>>
>> Do you know that the long int value can never exceed the range of int?  If
>> not, the static_cast will simply mask the problem.  It would be better to
>> check against std::numeric_limits<int>::max() before casting, and resort to
>> an exception if the range is exceeded.
>
> IIRC, that's boost::numeric_cast's purpose.

I would not suggest incurring a dependency on another file only to
avoid a warning.

Emil Dotchevski
Reverge Studios, Inc.
http://www.revergestudios.com/reblog/index.php?n=ReCode


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk