https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98261
Bug ID: 98261
Summary: Wrong optimize for virtual function
Product: gcc
Version: 11.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: 570070308 at qq dot com
Target Milestone: ---
In
```
#include <stdio.h>
#include <stdint.h>
class A
{
public:
virtual void print()
{
printf("A\n");
}
};
class B
{
public:
virtual void print()
{
printf("B\n");
}
};
int main()
{
A a;
B b;
A *pa=&a;
pa->print();
pa=(A *)&b;
pa->print();
return 0;
}
```
The compile is successful.
The program run normally in -O0. But in -O3 the program will print a lot of A
and distory.