Does compiler really enforce the implementation of the pure virtual destructor?
No the compiler does nothing like this.
The compiler compiles compilation units to object files, that's why it
compiled without any error.
I think nearly every compiler will compile this without any error. But the linker will complain. The compiler just adds code to object files, and also in- and outgoing references that are bound by the linker (for static linking).
Of course the program will not link if you comment-in the line Derived d;
again, see online demo.
Update
What you show in your question is just a single compilation unit, if you link it as a program, the linker will probably remove unused code. StorryTeller's answer says a lot about this.
If you comment-in the Derived
usage in main and copy the definition of Base
class into another compilation unit and add the destructor implementation there, you'll see that both will be linked together and the resulting program will run without any error. The compiler itself doesn't care if you include definitions from headers or not. I don't suggest to do this for productive programming but to understand why the compiler traditionally doesn't care about completeness of definitions. Most real-world compilation units are often incomplete.