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