Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
* [PATCH] gdb: fix variable shadowing error in darwin-nat.c
@ 2020-01-23 22:03 Simon Marchi
  2020-01-23 22:35 ` Tom Tromey
  0 siblings, 1 reply; 3+ messages in thread
From: Simon Marchi @ 2020-01-23 22:03 UTC (permalink / raw)
  To: gdb-patches; +Cc: Iain Sandoe, Simon Marchi

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/darwin-nat.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/gdb/darwin-nat.c b/gdb/darwin-nat.c
index 27677d16eae1..3bd8d8ce003d 100644
--- a/gdb/darwin-nat.c
+++ b/gdb/darwin-nat.c
@@ -1202,7 +1202,6 @@ darwin_nat_target::wait_1 (ptid_t ptid, struct target_waitstatus *status)
   mach_msg_header_t *hdr = &msgin.hdr;
   ptid_t res;
   darwin_thread_t *thread;
-  struct inferior *inf;
 
   inferior_debug
     (2, _("darwin_wait: waiting for a message pid=%d thread=%lx\n"),
@@ -1211,7 +1210,7 @@ darwin_nat_target::wait_1 (ptid_t ptid, struct target_waitstatus *status)
   /* Handle fake stop events at first.  */
   if (darwin_inf_fake_stop != NULL)
     {
-      inf = darwin_inf_fake_stop;
+      inferior *inf = darwin_inf_fake_stop;
       darwin_inf_fake_stop = NULL;
 
       darwin_inferior *priv = get_darwin_inferior (inf);
@@ -1250,6 +1249,7 @@ darwin_nat_target::wait_1 (ptid_t ptid, struct target_waitstatus *status)
       if (darwin_debug_flag > 10)
 	darwin_dump_message (hdr, darwin_debug_flag > 11);
 
+      inferior *inf;
       res = decode_message (hdr, &thread, &inf, status);
       if (res == minus_one_ptid)
 	continue;
@@ -1290,6 +1290,7 @@ darwin_nat_target::wait_1 (ptid_t ptid, struct target_waitstatus *status)
       if (darwin_debug_flag > 10)
 	darwin_dump_message (hdr, darwin_debug_flag > 11);
 
+      inferior *inf;
       ptid2 = decode_message (hdr, &thread, &inf, &status2);
 
       if (inf != NULL && thread != NULL
-- 
2.25.0


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] gdb: fix variable shadowing error in darwin-nat.c
  2020-01-23 22:03 [PATCH] gdb: fix variable shadowing error in darwin-nat.c Simon Marchi
@ 2020-01-23 22:35 ` Tom Tromey
  2020-01-23 22:49   ` Simon Marchi
  0 siblings, 1 reply; 3+ messages in thread
From: Tom Tromey @ 2020-01-23 22:35 UTC (permalink / raw)
  To: Simon Marchi; +Cc: gdb-patches, Iain Sandoe

>>>>> "Simon" == Simon Marchi <simon.marchi@efficios.com> writes:

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

I agree.  This looks good to me.

Tom


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] gdb: fix variable shadowing error in darwin-nat.c
  2020-01-23 22:35 ` Tom Tromey
@ 2020-01-23 22:49   ` Simon Marchi
  0 siblings, 0 replies; 3+ messages in thread
From: Simon Marchi @ 2020-01-23 22:49 UTC (permalink / raw)
  To: Tom Tromey, Simon Marchi; +Cc: gdb-patches, Iain Sandoe

On 2020-01-23 5:34 p.m., Tom Tromey wrote:
>>>>>> "Simon" == Simon Marchi <simon.marchi@efficios.com> writes:
> 
> Simon> Fix it by moving the declaration of `inf` in the specific scopes that
> Simon> need it.  I think it's clearer this way anyway, as it shows that it's
> Simon> not the same `inf` that is used in these different scopes.
> 
> I agree.  This looks good to me.
> 
> Tom
> 

Thanks, I pushed it.

Simon


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2020-01-23 22:45 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-01-23 22:03 [PATCH] gdb: fix variable shadowing error in darwin-nat.c Simon Marchi
2020-01-23 22:35 ` Tom Tromey
2020-01-23 22:49   ` Simon Marchi

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox