This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug c++/33470] New: Reassignment of a reference to a polymorphic class fails at runtime


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]