This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [PATCH] Fix -Wshadow warning in libiberty/cp-demangle.c
- From: Ian Lance Taylor <iant at google dot com>
- To: Mark Wielaard <mjw at redhat dot com>
- Cc: gcc-patches <gcc-patches at gcc dot gnu dot org>, Jason Merrill <jason at redhat dot com>, Paolo Bonzini <bonzini at gnu dot org>
- Date: Sat, 10 Sep 2016 01:57:54 -0700
- Subject: Re: [PATCH] Fix -Wshadow warning in libiberty/cp-demangle.c
- Authentication-results: sourceware.org; auth=none
- References: <1473466003-19517-1-git-send-email-mjw@redhat.com>
On Fri, Sep 9, 2016 at 5:06 PM, Mark Wielaard <mjw@redhat.com> wrote:
> valgrind contains a copy of the libiberty demangler which gets compiled
> with -Wshadow. That shows the following warning:
>
> cp-demangle.c: In function ‘d_substitution’:
> cp-demangle.c:3772:35: warning: declaration of ‘c’ shadows a previous local
> struct demangle_component *c;
> ^
> cp-demangle.c:3708:8: note: shadowed declaration is here
> char c;
> ^
>
> Fix that by renaming the struct demangle_component variable to dc
> and add -Wshadow to ac_libiberty_warn_cflags (the only warning is this one).
>
> libiberty/ChangeLog:
>
> * cp-demangle.c (d_substitution): Change struct demangle_component
> variable name from c to dc.
> * configure.ac (ac_libiberty_warn_cflags): Add -Wshadow.
> * configure: Regenerate.
The patch to cp-demangle.c is OK. Thanks.
I'm not sure about the patch to configure.ac/configure. The last I
looked -Wshadow would warn if a local variable shadows a global
variable. That can cause a pointless build break if some system
header file defines a global variable that happens to have the same
name as a local variable. It's not a likely scenario but I don't see
a need to court a build breakage.
Ian