GCC will not issue a compiler warning when a virtual inheritted method is 
hidden 
 
Steps: 
 
Use the following code to create a file named HideMethod.cpp 
 
class Parent 
{ 
public: 
    virtual ~Parent(){} 
    virtual void Method(){} 
}; 
 
class Child : public Parent 
{ 
public: 
    virtual void Method(int){} 
}; 
 
Compile the code with the following command. 
g++ -g -Wall -ansi -pedantic -c HideMethod.cpp 
 
Results: 
The code will compile with no warnings. 
 
Expected: 
The method Parent::Method() is hidden by the method Child::Method(int), and 
because the -Wall switch was used the compiler should issue a warning about 
this as it can lead to problems. 
 
Adding this code 
 
class GrandChild : public Child 
{ 
public: 
    void Test(){ Method(); } 
}; 
 
to HideMethod.cpp will correctly produce this error: 
 
HideMethod.cpp: In member function `void GrandChild::Test()': 
HideMethod.cpp:17: error: no matching function for call to 
`GrandChild::Method()' 
HideMethod.cpp:11: note: candidates are: virtual void Child::Method(int)

-- 
           Summary: GCC does not warn about hidden methods
           Product: gcc
           Version: 3.4.3
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: tron dot thomas at verizon dot net
                CC: gcc-bugs at gcc dot gnu dot org


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=18410

Reply via email to