When __cxa_deleted_virtual is called

I am trying to create a small test suite for avr C ++ scripts.

There are some "exceptional functions" that are usually provided from the C ++ library. Now I want to write a test program that creates this incorrect code, which should reference __cxa_deleted_virtual .

Can someone provide a piece of code that leads to a link to this function?

In fact, I have no idea how to create this "buggy" code.

+5
source share
1 answer

It was used to populate the vtable slot of a virtual function that was defined as remote:

 struct B { virtual void f() = delete; }; struct D : B { virtual void f() = delete; }; 

(The reason the remote virtual function is included in the vtable is because it allows you to subsequently change it to unidentified without breaking the vtable layout .)

I don't know how this could be called in (relatively normal) C ++, since the only thing that can override a function with a remote definition is another function with a remote definition ( [class.virtual] / 16 ), and any an attempt to call a function with a remote definition makes the program poorly formed. I suppose you can invoke the ghost of ODR violations:

 // TU 1 struct B { virtual void f() = delete; virtual void g(); }; void B::g() { } // causes vtable to be emitted in this TU // TU 2 struct B { virtual void f(); virtual void g(); }; void h(B* b) { b->f(); } int main() { B b; h(&b); } 
+2
source

All Articles