Boost logo

Boost :

From: David Abrahams (dave_at_[hidden])
Date: 2003-11-16 17:47:17


"Stephan T. Lavavej" <stl_at_[hidden]> writes:

> [David Abrahams]
>> I am reluctant to cater to every possible warning. This is an
>> example of one which often flags perfectly good code.
>
> But is it really perfectly good code?
>
> Quoth the GCC Manual, "Warnings are diagnostic messages that report
> constructions which are not inherently erroneous but which are risky or
> suggest there may have been an error."
>
> Code with shadowed variables can be completely correct, but shadowing is
> still risky. Thus, I /don't/ think that code which -Wshadow complains about
> is perfectly good code.
>
> Unlike some warnings which are difficult to fix, shadowing can always be
> avoided easily: simply rename the offending variable. (If it's hard to
> figure out what a given name refers to, then that's all the more reason that
> the shadowing should be eliminated.) Shadowing adds zero power or
> convenience, but does add danger.

It depends if you're shadowing some inherited implementation detail
which you didn't put there and don't care about.

>> Should we try to come to a concensus about this?
>
> A decision one way or the other would be nice.
>
> If you decide that Boost shouldn't be -Wshadow clean, then at the very least
> it would be nice to add a #pragma GCC system_header to each header file when
> they're being used by users and not developers. Otherwise, using Boost will
> make -Wshadow useless, which is just as bad as, say, polluting the user's
> namespace.

Be happy to, once you convince the GCC developers to start supporting
#pragmas ;-)

>> Should we go the other direction, and simply enable all warnings in our
>> Boost.Build toolsets?
>
> The warnings that I compile my own code with are:
>
> -Wall -W -Wfloat-equal -Wshadow -Wpointer-arith -Wcast-qual -Wcast-align
> -Wwrite-strings -Wconversion -fno-nonansi-builtins -Wold-style-cast
> -Woverloaded-virtual

OK, but what makes your set of warnings the right set?

-- 
Dave Abrahams
Boost Consulting
www.boost-consulting.com

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