[Bug c++/56556] New: Wshadow warns for private members in base classes

david at doublewise dot net gcc-bugzilla@gcc.gnu.org
Thu Mar 7 00:44:00 GMT 2013


             Bug #: 56556
           Summary: Wshadow warns for private members in base classes
    Classification: Unclassified
           Product: gcc
           Version: 4.7.2
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: david@doublewise.net

The following code warns due to -Wshadow:

class Base {
    int x;

class Derived : public Base {
    Derived(int x) {}

Perhaps we should consider not having this warn? In my particular case, I have
a Base class with a private member variable, a class Derived that derives from
Base, and a class EvenMoreDerived that derives from Derived. In a member
function of EvenMoreDerived, I am trying to use a variable with the same name
as the private member variable of Base.

The only situation I can think of where this could theoretically be useful is
if there is some kind of overload resolution issue, but due to derived classes
hiding member functions of base classes I don't imagine that would be an issue.

More information about the Gcc-bugs mailing list