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



             Bug #: 55385

           Summary: g++ failed to call final overrider of a virtual

                    function.

    Classification: Unclassified

           Product: gcc

           Version: 4.7.0

            Status: UNCONFIRMED

          Severity: normal

          Priority: P3

         Component: c++

        AssignedTo: unassig...@gcc.gnu.org

        ReportedBy: m...@g.clemson.edu





The code below is adapted from the example code given in 10.3/2 of the current

standard.



--------------- BEGIN ---------------

#include <iostream>



struct A {

 virtual void f() { std::cout << "A::f" << std::endl; }

};

struct B : virtual A {

 virtual void f() { std::cout << "B::f" << std::endl; }

};

struct C : B , virtual A {

 using A::f;

};

void foo() {

 C c;

 c.f();    // (1) calls B::f, the final overrider

 c.C::f(); // (2) calls A::f because of the using-declaration

}



int main ()

{

 foo();

 return 0;

}

---------------  END  ---------------



The standard says that c.f() should call B::f because it is the final overrider

in C of the virtual function f. According to my test on g++-4.7.0, however,

both call A::f.



My compile command line is: ~/gcc/4.7.0/bin/c++ -O3 -Wall -Wextra t.cc

My compiler version is: 

Reading specs from /home/meng/gcc/4.7.0/lib/gcc/i686-pc-linux-gnu/4.7.0/specs

COLLECT_GCC=/home/meng/gcc/4.7.0/bin/c++

COLLECT_LTO_WRAPPER=/home/meng/gcc/4.7.0/libexec/gcc/i686-pc-linux-gnu/4.7.0/lto-wrapper

Target: i686-pc-linux-gnu

Configured with: ./configure --prefix=/home/meng/gcc/4.7.0/

--enable-languages=c,c++

Thread model: posix

gcc version 4.7.0 (GCC)

Reply via email to