Re: -Wshadow option vs. init lists

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Fri, 2016-10-28 at 19:24 +0100, Jonathan Wakely wrote:
> On 28 October 2016 at 06:57, Paul Smith wrote:
> > 
> > (using GCC 6.2 on a GNU/Linux system):
> > 
> >    class Foo
> >    {
> >        int foo;
> >    public:
> >        Foo(int foo) : foo(foo) {}
> >    };
> > 
> > Clang has an additional warning flag, -Wshadow-field-in-
> > constructor.  There, it's not enabled by default with -Wshadow but
> > even if it were in GCC and I was able to add -Wno-shadow-field-in-
> > constructor I would be happy.
> > 
> > What do people think about making a special case for -Wshadow,
> > either that it will never warn for this specific situation (where
> > the parameter is used to initialize a member variable of the same
> > name, which would cover 90% of my cases) or adding a new option to
> > turn off warnings like this in constructor parameters completely,
> > like clang does?
> 
> Sounds good to me. I agree there's nothing wrong with the code.

I filed https://gcc.gnu.org/bugzilla/show_bug.cgi?id=78147 with my
quick-and-dirty patch to permanently disable the warning in ctor param
lists, just as an example.  Adding a command-line option is to-be-done.

To be clear this disables the warning for all ctor parameters, since
that's where the warning is emitted (not where the parameter is used).
Trying to make this only warn if not being used in an initializer list
would be, from what I can see, significantly more effort.

Any comments anyone has on that bug would be welcome.

Cheers!



[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux