AnsweredAssumed Answered

Suspected c++ compiler bug in CodeWarrior for ColdFire V6.4

Question asked by Henry Hei on Mar 31, 2017
Latest reply on Apr 9, 2017 by Henry Hei

I'm maintaining an old product based on MCF5208, I found some code behavior is strange, so I wrote a simple test code to do test. I think I found a compiler bug when using C++ virtual  function.

class A
{
public:
virtual int Size()=0;
};

class B:public A
{
public:
virtual int Size()
{
return 10;
}

};

static B b;


void test(void)
{
A *p = &b;
int x = b.Size();
int y= p->Size();
int z=x+y;
}

 

When code run to p->Size(); it will crash.

 

I have decompiled the code and run it in step mode, I found it crashed in the line I marked red.

 

 

Is this a real problem or it just because of some incorrect compiler settings?

Outcomes