Boost logo

Boost :

Subject: Re: [boost] [units] gcc warnings
From: Stewart, Robert (Robert.Stewart_at_[hidden])
Date: 2010-06-15 12:50:40

Emil Dotchevski wrote:
> On Tue, Jun 15, 2010 at 3:55 AM, Stewart, Robert
> <Robert.Stewart_at_[hidden]> 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"
> >
> >> /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.
> With or without the static_cast, if the long int value exceeds the
> range of an int you're screwed. The only difference the cast makes is
> that you won't get the warning.

You snipped the part in which I suggested an exception to indicate the overflow. That leaves the error handling to the calling code.

> The problem with using casts to silence warnings is that silencing the
> warning is a side effect of altering of the behavior of what is
> usually a correct program.

I can't quite parse that, but I was advocating against the OP's plan to simply mask the conversion with a cast.

I have to wonder if you actually meant to reply to the OP and not me.

Rob Stewart robert.stewart_at_[hidden]
Software Engineer, Core Software using std::disclaimer;
Susquehanna International Group, LLP

IMPORTANT: The information contained in this email and/or its attachments is confidential. If you are not the intended recipient, please notify the sender immediately by reply and immediately delete this message and all its attachments. Any review, use, reproduction, disclosure or dissemination of this message or any attachment by an unintended recipient is strictly prohibited. Neither this message nor any attachment is intended as or should be construed as an offer, solicitation or recommendation to buy or sell any security or other financial instrument. Neither the sender, his or her employer nor any of their respective affiliates makes any warranties as to the completeness or accuracy of any of the information contained herein or that this message or any of its attachments is free of viruses.

Boost list run by bdawes at, gregod at, cpdaniel at, john at