|
Boost : |
Subject: Re: [boost] Towards a Warning free code policy proposal
From: Mika Heiskanen (mika.heiskanen_at_[hidden])
Date: 2010-08-29 03:17:04
On Sun, 2010-08-29 at 09:23 +0300, Emil Dotchevski wrote:
> On Sat, Aug 28, 2010 at 2:11 PM, Mika Heiskanen <mika.heiskanen_at_[hidden]> wrote:
> > In my experience this warning is just about always the result of
> > using int for variables which should be of type size_t, as in
> >
> > for(int i=0; i<object.size(); i++)
> >
> > If I cannot redefine all the types to unsigned, something like this
> > usually fixes the problem:
> >
> > if ( size >= 0 && static_cast<size_t>(size) < object.size() )
> >
> > Writing static_casts is annoying, but it is often necessary
> > if you want to remain -Wall -pedantic.
>
> This is a good illustration of one of the problems with "fixing"
> warnings: this is often done with casts, and casts are way more
> dangerous than the built-in implicit conversions for which the
> compiler is warning about.
I did try to imply changing size types to be unsigned is the better
solution, since then there will be nothing to warn about. With 3rd
party libraries that is not always possible, and for me boost is a 3rd
party library. Having said that, I do not recall ever having to
static_cast anything when using boost, the warnings usually appear
when using legacy code.
--> Mika Heiskanen
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk