Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Mark Kettenis <mark.kettenis@xs4all.nl>
To: eliz@gnu.org
Cc: brobecker@adacore.com, andrew.smirnov@gmail.com,
	       gdb-patches@sourceware.org
Subject: Re: [PATCH 18/348] Fix -Wsahdow warnings
Date: Fri, 25 Nov 2011 16:26:00 -0000	[thread overview]
Message-ID: <201111251626.pAPGQ3rN016558@glazunov.sibelius.xs4all.nl> (raw)
In-Reply-To: <83ehww8b1t.fsf@gnu.org> (message from Eli Zaretskii on Fri, 25	Nov 2011 17:41:02 +0200)

> Date: Fri, 25 Nov 2011 17:41:02 +0200
> From: Eli Zaretskii <eliz@gnu.org>
> 
> > Date: Fri, 25 Nov 2011 16:11:11 +0100 (CET)
> > From: Mark Kettenis <mark.kettenis@xs4all.nl>
> > 
> > > If it surprised you, it means -Wsahdow did its job well.
> > 
> > No it didn't.  It does a poor job, by flagging cases that can never
> > ever cause problems.  A local variable "shadowing" a global function
> > name will never be a problem, because something like:
> > 
> > void foo(void);
> > 
> > void
> > bar(void)
> > {
> > 	int foo;
> > 
> > 	foo();
> > }
> > 
> > simply won't compile, even if you don't use -Werror.
> 
> But the patches suggested by Andrey didn't find any instances of the
> above.  So I submit that this danger is purely theoretical at this
> point, or at least sufficiently rare in GDB to render this
> consideration not important in practice for us.

You're missing my point.

A significant number of Andrey's changes (all-but-one of the ones I
looked at) rename *local* variables because they have the same name as
a function.  My example above tries to show you that there is
absolutely no problem with that, because if one wouldf accidentally
try to invoke the function that has the same name as the local
variable, the compiler would already generate an error.

> > > IOW, it's easy to avoid well-known names like `printf' or `strchr'.
> > > It's the not-so-well-known names that give you hell and high water.
> > 
> > Exactly.  And since we enable -Werror by default, -Wshadow will break
> > GDB builds for no good reason.
> 
> Clashing with library symbols _is_ a good reason to prevent GDB from
> building.

For *local* variables?  

> > And remove some perfectly usable and meaningful variable names.
> 
> They can be easily replaced by no less meaningful and usable ones.

But such a change requires one to actually read and understand the
code.  Such changes can therefore never be obvious, so they can't be
fixed quickly.

> > > In general, we have no bullet-proof way of making sure our code works
> > > on all supported platforms, except by actually compiling it on those
> > > platforms.  That's why platforms which lose their area maintainers
> > > bit-rot quite quickly.  This compiler switch doesn't change this
> > > situation in any way.
> > 
> > I disagree.  -Wshadow is a game changer because actually compiling on
> > *all* plaforms is the only way to make sure that I don't actually
> > break anything.  That's extremely bad!
> 
> The same is true of any code you add or change, with the possible
> exception of very trivial changes.

For most changes, compiling on one system gives you reasonable
confidence that things work on other systems as well.

> > Most people that contribute to GDB are fairly competent programmers.
> 
> Being competent doesn't mean being clairvoyant.  How can we trust
> ourselves to know by heart every single symbol in the standard
> libraries?

Exactly!  That's why -Wshadow is so bad.  Our "defs.h" pulls in lots
of system headers.  And on top of that we use options like
_GNU_SOURCE, which invite the system to pollute the global namespace
as much as it want.

Since there is absolutely no problem with a local variable that has
the same name as a library function, this is bad.


  reply	other threads:[~2011-11-25 16:26 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-11-22 13:01 Andrey Smirnov
2011-11-22 18:03 ` Tom Tromey
2011-11-23 16:36 ` Mark Kettenis
2011-11-23 16:41   ` Ulrich Weigand
2011-11-23 18:21     ` Pedro Alves
2011-11-23 18:42       ` Joel Brobecker
2011-11-23 20:24       ` Mark Kettenis
2011-11-24  4:16         ` Andrey Smirnov
2011-11-24 11:36           ` Eli Zaretskii
2011-11-24 22:01           ` Joel Brobecker
2011-11-25  0:48             ` Andrey Smirnov
2011-11-25 14:26               ` Joel Brobecker
2011-11-25 15:52                 ` About adding -Wshadow option by default (was Re: [PATCH 18/348] Fix -Wsahdow warnings) Pierre Muller
2011-11-25 16:36                   ` Mark Kettenis
2011-11-29 19:18                 ` [PATCH 18/348] Fix -Wsahdow warnings Tom Tromey
2011-11-30  3:48                   ` Andrey Smirnov
2011-11-30 14:59                     ` Tom Tromey
2011-12-01  4:15                       ` Andrey Smirnov
2011-12-02 17:08                         ` Tom Tromey
2011-11-25 12:03             ` Eli Zaretskii
2011-11-25 15:11               ` Mark Kettenis
2011-11-25 15:41                 ` Eli Zaretskii
2011-11-25 16:26                   ` Mark Kettenis [this message]
2011-11-25 18:20                     ` Eli Zaretskii
2011-11-27 13:53                       ` Mark Kettenis
2011-11-27 14:55                         ` Pedro Alves
2011-11-27 16:35                         ` Eli Zaretskii

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=201111251626.pAPGQ3rN016558@glazunov.sibelius.xs4all.nl \
    --to=mark.kettenis@xs4all.nl \
    --cc=andrew.smirnov@gmail.com \
    --cc=brobecker@adacore.com \
    --cc=eliz@gnu.org \
    --cc=gdb-patches@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox