public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
From: Jason Merrill <jason@redhat.com>
To: Bernd Edlinger <bernd.edlinger@hotmail.de>
Cc: Richard Biener <richard.guenther@gmail.com>,
	gcc Mailing List <gcc@gcc.gnu.org>
Subject: Re: Adding -Wshadow=local to gcc build rules
Date: Fri, 20 Sep 2019 19:13:00 -0000	[thread overview]
Message-ID: <CADzB+2=TtG5u-MzKMGs9pREUVY56DhLnbiw2qaX8=fVwNzKsGw@mail.gmail.com> (raw)
In-Reply-To: <AM6PR10MB2566D779142A457E1F46B96DE4880@AM6PR10MB2566.EURPRD10.PROD.OUTLOOK.COM>

On Fri, Sep 20, 2019, 2:21 PM Bernd Edlinger <bernd.edlinger@hotmail.de>
wrote:

> On 9/19/19 12:19 PM, Richard Biener wrote:
> > On Wed, Sep 18, 2019 at 3:09 PM Bernd Edlinger
> > <bernd.edlinger@hotmail.de> wrote:
> >>
> >> Hi,
> >>
> >> I'm currently trying to add -Wshadow=local to the gcc build rules.
> >> I started with -Wshadow, but gave up that idea immediately.
> >>
> >> As you could expect the current code base has plenty of shadowed
> >> local variables.  Most are trivial to resolve, some are less trivial.
> >> I am not finished yet, but it is clear that it will be a rather big
> >> patch.
> >>
> >> I would like to ask you if you agree that would be a desirable step,
> >> in improving code quality in the gcc tree.
> >
> > I wonder if -Wshadow=compatible-local is easier to achieve?
> >
>
> I tried that and it does not make a big difference, while
> it misses for instance:
>
> * gcc/c-family/c-ada-spec.c (dump_ada_macros)
> unsigned char *s, shadowed by const unsigned char *s. :-/
>
> On the other hand, -Wshadow=global is a lot more difficult,
> because we have lots of globals, for instance:
>
> context.h:
> /* The global singleton context aka "g".
>    (the name is chosen to be easy to type in a debugger).  */
> extern gcc::context *g;
>
> But unfortunately Wshadow=local does not find class members
> shadowed by local variable, which happens for instance in
> wide-int
>
> With -Wshadow, I had to change this in wide-int.h:
>
> Index: gcc/wide-int.h
> ===================================================================
> --- gcc/wide-int.h      (revision 275545)
> +++ gcc/wide-int.h      (working copy)
> @@ -648,9 +648,9 @@ namespace wi
>      storage_ref () {}
>      storage_ref (const HOST_WIDE_INT *, unsigned int, unsigned int);
>
> -    const HOST_WIDE_INT *val;
> -    unsigned int len;
> -    unsigned int precision;
> +    const HOST_WIDE_INT *m_val;
> +    unsigned int m_len;
> +    unsigned int m_precision;
>
>
> So this change was not necessary for -Wshadow=local, although
> I would think that, shadowing class members is not much different from
> shadowing a local scope.
>
> Not sure if shadowing class members should be part of -Wshadow=local
> instead of -Wshadow=global.
>

That would make sense to me.

>

  reply	other threads:[~2019-09-20 19:13 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-09-18 13:08 Bernd Edlinger
2019-09-18 13:39 ` Martin Liška
2019-09-18 15:16 ` Tom Tromey
2019-09-19 10:20 ` Richard Biener
2019-09-20 18:20   ` Bernd Edlinger
2019-09-20 19:13     ` Jason Merrill [this message]
2019-09-21  9:44 ` Segher Boessenkool
2019-10-02 19:10 ` Bernd Edlinger

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='CADzB+2=TtG5u-MzKMGs9pREUVY56DhLnbiw2qaX8=fVwNzKsGw@mail.gmail.com' \
    --to=jason@redhat.com \
    --cc=bernd.edlinger@hotmail.de \
    --cc=gcc@gcc.gnu.org \
    --cc=richard.guenther@gmail.com \
    /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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).