class A { public: A() { } protected: int aaa; }; class B:public A { public: B():A() { } protected: int aaa; }; compiles without a warning, and is a potential source of hard to trace problems (while it can, of course, be used intentionally). It may be useful to give a warning akin to the one given in the case of void blah(int a) { int a; }
Right. Makes sense. W.
I agree. I hope this warning will be added in near future versions of g++.
Reconfirming with GCC 11.0.
*** Bug 45615 has been marked as a duplicate of this bug. ***
is this expected to be a new argument accepted by the `-Wshadow=` flag, or its own separate flag entirely?
This inheritance case is "name hiding" and we have other requests for warnings about it. I think it should be distinct from -Wshadow.
Hi, I'm currently fixing this, I've put it under -Wshadow for now, as it is still about shadowing names, but I could add a -Wname-hiding or something akin to it. What about the visibility of the base class field ? I think that in snippet (1) below, a warning should be issued, as we can imagine Base being virtual with private field x and a friend function foo(Base*) taking polymorphic argument Base*, then Derived inherits of Base, with public field x. There might be an ambiguity upon accessing x in a call to foo((Base *) derived). Therefore, I believe the warning should be issued no matter the visibility of the fields within the parent's class. However, if Grandpa class is privately inherited by Base class, then I'd expect Derived to not issue warnings for its fields named only after Grandpa's. // Snippet (1) class Base { private: int x; }; class Derived : public Base { public: int x; // issue warning despite Base::x private }; // Snippet (2) class Grandpa; class Base : private Grandpa; class Derived : public Base; // No warnings emitted for eponymous fields of Grandpa's