On Mon, Jun 22, 2009 at 09:45:52PM -0400, Robert Dewar wrote:
> Joe Buck wrote:
>> I think that this should be the standard: a warning belongs in -Wall if
>> it tends to expose bugs.  If it doesn't, then it's just somebody's idea
>> of proper coding style but with no evidence in support of its correctness.
>>
>> A -Wall warning should expose bugs, and should be easy to silence in
>> correct code.
>
> To understand what you are saying, we need to know what bug means, since
> it can have two meanings:
>
> 1. An actual error, that could show up right now in certain circumstances
>
> 2. An error resulting in undefined behavior in the standard, but
> for the current version of gcc, it cannot actually cause any real
> misbehavior, but some future version of gcc might take advantage
> of this error status and do something weird.
>
> For me it is enough if warnings expose case 2 situations, even if
> they find few if any case 1 situations.

I agree, but I think this warning should be in -Wc++-compat, not -Wall
or even -Wextra.  Why?  I'd argue the warning is useless for C code,
unless you care about C++ style.

There were five places in binutils that triggered -Wjump-misses-init
warnings.  Not one of them was a real bug, even using Robert's case 2
definition.  I believe the same is true of the three places in gcc
where the warning triggered.

So far, no one has generated a C testcase having undefined behaviour
where -Wjump-misses-init warns but -Wuninitialized (already in -Wall)
doesn't, when optimizing.  If such a testcase is found, I'm guessing
it probably should be filed as a -Wuninitialized bug.

In C, an auto variable initialization is just an assignment.  (I'm of
course aware that arrays can be initialized and their size set,
structs and unions initialized, but by and large, in C, an
initialization is simply an assignment.)  So, why single out the
initial assignment?  If skipping it deserves a warning then skipping
other assignments deserves a warning too, which would be ridiculous.

-- 
Alan Modra
Australia Development Lab, IBM

Reply via email to