In a freestanding context (no standard libraries, e.g. in operating system development) using g++ the following phenomenon occurs:
class Base {
public:
virtual ~Base() {}
};
class Derived : public Base {
public:
~Derived() {}
};
int main() {
Derived d;
}
When linking it states something like this: undefined reference to operator delete(void*)
Which clearly means that g++ is generating calls to delete operator even though there are zero dynamic memory allocations. This doesn't happen if destructor isn't virtual.
I suspect this has to do with the generated vtable for the class but I'm not entirely sure. Why does this happen?
If I must not declare a delete operator due to the lack of dynamic memory allocation routines, is there a work around?
EDIT1:
To successfully reproduce the problem in g++ 5.1 I used:
g++ -ffreestanding -nostdlib foo.cpp