This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/33470] New: Reassignment of a reference to a polymorphic class fails at runtime
- From: "photon at seznam dot cz" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 18 Sep 2007 10:49:17 -0000
- Subject: [Bug c++/33470] New: Reassignment of a reference to a polymorphic class fails at runtime
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
The following code compiles cleanly with 4.2.1. The expected output is "C" but
the executable outputs "B".
#include <iostream>
using namespace std;
struct A
{
virtual ~A() { }
virtual void f() { cout << "A"; }
};
struct B : public A
{
virtual void f() { cout << "B"; }
};
struct C : public A
{
virtual void f() { cout << "C"; }
};
int main(int argc, char **argv)
{
B Binst;
C Cinst;
A &Aref = Binst;
Aref = Cinst;
Aref.f();
return 0;
}
--
Summary: Reassignment of a reference to a polymorphic class fails
at runtime
Product: gcc
Version: 4.2.1
Status: UNCONFIRMED
Severity: major
Priority: P3
Component: c++
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: photon at seznam dot cz
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=33470