gdb: fix variable shadowing error in darwin-nat.c
authorSimon Marchi <simon.marchi@efficios.com>
Thu, 23 Jan 2020 22:44:22 +0000 (17:44 -0500)
committerSimon Marchi <simon.marchi@efficios.com>
Thu, 23 Jan 2020 22:44:22 +0000 (17:44 -0500)
commitab53f3826242df0f051f9a6fa4b2926687205025
tree238c13ce97c77ffc1884a8bb1d910e3fdd6b9198
parente7eee665a1524cc4569d0c2f5c9d4aa2be64c9e8
gdb: fix variable shadowing error in darwin-nat.c

We encounter this error when building on macOS with GCC.

  CXX    darwin-nat.o
/src-local/binutils-gdb/gdb/darwin-nat.c: In member function 'ptid_t darwin_nat_target::wait_1(ptid_t, target_waitstatus*)':
/src-local/binutils-gdb/gdb/darwin-nat.c:1264:18: error: declaration of 'inf' shadows a previous local [-Werror=shadow=compatible-local]
   for (inferior *inf : all_inferiors (this))
                  ^~~
/src-local/binutils-gdb/gdb/darwin-nat.c:1205:20: note: shadowed declaration is here
   struct inferior *inf;
                    ^~~

Fix it by moving the declaration of `inf` in the specific scopes that
need it.  I think it's clearer this way anyway, as it shows that it's
not the same `inf` that is used in these different scopes.

Thanks to Iain Sandoe for reporting this.  I did not see this error at
first, because I compile with the default system compiler on macOS,
which is clang.  The compiler flag we try to enable for this is
`-Wshadow=local`, which is not one recognized by clang.  I checked to
see if there would a version of the -Wshadow* warnings [1] we could
enable for clang, that would catch this, but the only one that would is
`-Wshadow` itself, and this is too invasive for us (which is why we
enabled just -Wshadow=local in the first place).

[1] https://clang.llvm.org/docs/DiagnosticsReference.html#wshadow

gdb/ChangeLog:

* darwin-nat.c (darwin_nat_target::wait_1): Move `inf`
declaration to narrower scopes.
gdb/ChangeLog
gdb/darwin-nat.c
This page took 0.026766 seconds and 4 git commands to generate.