This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
[PATCH 0/8] Add -Wshadow=local
- From: Tom Tromey <tom at tromey dot com>
- To: gdb-patches at sourceware dot org
- Date: Sat, 22 Sep 2018 22:08:06 -0600
- Subject: [PATCH 0/8] Add -Wshadow=local
This series enables -Wshadow=local for gdb.
I think that shadowing is mildly confusing, and I normally try to
avoid it. However, for a long time, it wasn't feasible to enable any
shadowing warnings, because gcc would warn about shadowing that was
"uninteresting" -- the classic example being the use of a local
variable named "index".
In this series I chose to use -Wshadow=local, to forbid shadowing
within a function. -Wshadow=compatible-local is another choice, but I
think that the stated semantics:
In C++, type compatibility here means the type of the shadowing
variable can be converted to that of the shadowed variable.
... is maybe insufficient. For example a situation where the two
different types are both convertible to a third type could be enough
to cause a bug. That's a bit of a reach maybe, but it seemed to me
that it's not such a big deal, and certainly always safer, to just
disallow shadowing entirely.
Adding this warning found a few latent bugs in gdb.
Regression tested by the buildbot. Thanks, Sergio, for your work
running this -- it is a great service.
Let me know what you think. I feel that a change like this should
involve some feedback.
Tom