This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/11750] New: Incorrect virtual method invoked for class hierarchy w/ virtual bases
- From: "jfischer_5809 at yahoo dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 31 Jul 2003 17:44:51 -0000
- Subject: [Bug c++/11750] New: Incorrect virtual method invoked for class hierarchy w/ virtual bases
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
PLEASE REPLY TO gcc-bugzilla@gcc.gnu.org ONLY, *NOT* gcc-bugs@gcc.gnu.org.
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=11750
Summary: Incorrect virtual method invoked for class hierarchy w/
virtual bases
Product: gcc
Version: 3.3
Status: UNCONFIRMED
Severity: normal
Priority: P2
Component: c++
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: jfischer_5809 at yahoo dot com
CC: gcc-bugs at gcc dot gnu dot org
GCC build triplet: i686-pc-linux-gnu
GCC host triplet: i686-pc-linux-gnu
GCC target triplet: i686-pc-linux-gnu
Paragraph 10.3/2 in the C++ standard [ISO/IEC 14882:1998] provides the following
code example:
<quote>
struct A {
virtual void f();
};
struct B : virtual A {
virtual void f();
};
struct C : B , virtual A {
using A::f;
};
void foo() {
C c;
c.f(); // calls B::f, the final overrider
c.C::f(); // calls A::f because of the using-declaration
}
</quote>
When a similar program is compiled using G++ 3.3, the method call 'c.f()' in
function foo() incorrectly invokes A::f and not B::f as specified in the standard.
<example>
<code main.cpp>
#include <iostream>
struct A {
virtual void f() { std::cout << "A::f()\n"; }
};
struct B : virtual A {
virtual void f() { std::cout << "B::f()\n"; }
};
struct C : B, virtual A {
using A::f;
};
int main()
{
C c;
c.f(); // ERROR - Incorrectly invokes A::f
c.C::f(); // OK - Invokes A::f
}
</code>
<build>
$ g++ main.cpp
$ ldd a.out
libstdc++.so.5 =>
/usr/local/gcc/3.3/lib/gcc-lib/i686-pc-linux-gnu/3.3/libstdc++.so.5 (0x40017000)
libm.so.6 => /lib/tls/libm.so.6 (0x400e4000)
libgcc_s.so.1 =>
/usr/local/gcc/3.3/lib/gcc-lib/i686-pc-linux-gnu/3.3/libgcc_s.so.1 (0x40106000)
libc.so.6 => /lib/tls/libc.so.6 (0x42000000)
/lib/ld-linux.so.2 => /lib/ld-linux.so.2 (0x40000000)
</build>
<output>
$ ./a.out
A::f()
A::f()
</output>
</example>