Shadow data member

Nick Savoiu savoiu@yahoo.com
Mon Oct 11 16:15:30 GMT 2021


I'm not sure what the proper name is but, IMO, it might be a good thing to warn about as it could result in the same kind of unexpected results as when removing a shadowing local variable.

Nick




On Wednesday, September 29, 2021, 01:56:37 PM PDT, Jonathan Wakely <jwakely.gcc@gmail.com> wrote: 





On Wed, 29 Sept 2021 at 21:46, Nick Savoiu via Gcc-help

<gcc-help@gcc.gnu.org> wrote:
>
> Should GCC report shadowing on 'valid' for this code?
>
> Nick
>
> struct S1{    bool valid;};
> struct S2 : public S1{    bool valid;};
> struct S3 : public S2{    bool valid;};


IMHO, no, because this is name hiding, now shadowing.

The documentation for the -Wshadow warnings is clear that it refers to
local variables. For class members you can still access the base one
by qualifying it, i.e. S1::valid, S2::valid.



More information about the Gcc-help mailing list