I try to build a little test case set for avr c++ builds.
There are some "exceptional functions" provided typically from the c++ library. Now I want to write a test program which produces this wrong code which must link to __cxa_deleted_virtual
.
Can anyone provide a code snippet which results in linking to that function?
I have actually no idea how to produce this "buggy" code.
It's used to fill the vtable slot of a virtual function that has been defined as deleted:
struct B { virtual void f() = delete; };
struct D : B { virtual void f() = delete; };
(The reason a deleted virtual function is included in the vtable is that this allows it to be later changed to non-deleted without breaking vtable layout.)
I'm not aware of any way it could actually get called in (relatively sane) C++, since the only thing that can override a function with a deleted definition is another function with a deleted definition ([class.virtual]/16), and any attempt to call a function with a deleted definition renders the program ill-formed. I suppose you can invoke the specter 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);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With