Why is derived class destructor not called in clang

Viewed 70

Why is the derived destructor not called with clang++ 10, it works as expected with g++ 9? Why do I get

BC 
DC 
BD 

Instead of

BC 
DC 
DD 
BD 

struct AA
{
    AA()
    {
        cout <<"BC"<<endl;
    }
    virtual ~AA()
    {
        cout <<"BD"<<endl;
    }    
};
struct AB: public AA
{
    AB()
    {
        cout <<"DC"<<endl;
    }
    ~AB() override
    {
        cout <<"DD"<<endl;
    }

};
    
int main()
{
    AA *x= new AB[1];
    delete [] x;
    return 0;
}
0 Answers
Related