Jeff Law wrote:
> I prefer consistency in warnings, regardless of optimization level.
I disagree and I think we have a significant contingency of
users that would disagree -- if optimizations allow us to avoid
false-positive warnings, then we should use that information to
avoid those false positive warnings.
Jeff, I completely agree with you for some class of users (users being
developers who use GCC but don't hack on GCC itself).
OTOH, there is also a very large class of users (like myself) who have to
write code that works well across several different compilers. In this
capacity, having GCC be clever is not a good thing: if GCC is silent where
a less clever compiler will warn, I will have to fix the warning *anyway*
and won't know about it until someone else complains (I use GCC as my
primary development compiler).
In addition, I will assert that GCC's cleverness often causes it to emit
FAR MORE warnings than those compilers that are not clever. For example,
consider the following code:
int X;
if (somepredicate(A, &X))
use X;
Prior versions of GCC (and most other compilers) assumed that since
somepredicate is passed the address of X, that it may initialize X, thus
not emitting a warning at the use site. Newer versions of GCC inline
somepredicate and then emit a bogus warning: "X" is only assigned to (and
used) in the case where somepredicate returns true, and GCC loses this
information (it is probably missing a jump threading opportunity).
While the above case can certainly be fixed in the future, the point is
that every time a new GCC version comes out, we have to add MORE
initializers to silence bogus warnings: its cleverness has inevitably (at
least for 3.4, 4.0, and 4.1 mainline) resulted in more bogus warnings
being emitted. I don't see any way to stop this, as there will always be
cases that cannot be handled, and the optimizers are a fundamentally
fragile thing to depend on for this (this being part of GCC's "user
exprerience").
For users like myself, I would really like to have an option to switch the
unused var warning to be emitted from the *front-end* where it works when
compiling with optimization disabled (a huge feature in itself) and where
the warnings are more stable. I know that it is impossible to guarantee
that GCC will ever match "other compilers", and that there will be false
positives (e.g. double diamond patterns), but for many uses this is
perfectly fine (other compilers warn about the same cases, so these cases
already have initializers).
This is just MHO, but I know that many other developers are in a similar
boat.
-Chris
--
http://nondot.org/sabre/
http://llvm.org/