This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/78632] Produce warning when a derived class shadows a field of the base class with `-Wshadow`
- From: "egallager at gcc dot gnu.org" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Tue, 22 Aug 2017 20:40:52 +0000
- Subject: [Bug c++/78632] Produce warning when a derived class shadows a field of the base class with `-Wshadow`
- Auto-submitted: auto-generated
- References: <bug-78632-4@http.gcc.gnu.org/bugzilla/>
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=78632
Eric Gallager <egallager at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Keywords| |diagnostic
Status|UNCONFIRMED |NEW
Last reconfirmed| |2017-08-22
CC| |egallager at gcc dot gnu.org
Ever confirmed|0 |1
--- Comment #2 from Eric Gallager <egallager at gcc dot gnu.org> ---
(In reply to Vittorio Romeo from comment #0)
> struct Base { int a; };
> struct Derived : Base { int a; };
> int main() { }
>
> The code snippet above produces no warnings with `-Wshadow` enabled.
> This seems like an unusual situation that could lead to unexpected behavior.
>
> I suggest producing a warning when `-Wshadow` is enabled, to alert that
> `Derived::a` is shadowing `Base::a`.
>
> Related SO question:
> https://stackoverflow.com/questions/40908402
Confirmed that no warnings are produced.
(In reply to Vittorio Romeo from comment #1)
> Forgot to set an appropriate importance level, and I can't seem to edit it.
> Sorry.
That's okay, leaving it as the default is probably better.