-Wshadow option vs. init lists
Paul Smith
psmith@gnu.org
Fri Oct 28 18:48:00 GMT 2016
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!
More information about the Gcc-help
mailing list