clang warns on missing virtual destructors if a polymorphic delete is used. I.e. clang will will warn on
class A {
virtual void f() {}
};
void f() {
A* a = FunctionReturningA();
delete a;
}
test.cc:9:3: warning: delete called on 'A' that has virtual functions but non-virtual destructor [-Wdelete-non-virtual-dtor]
delete a;
^
1 warning generated.
clang won't warn if A is never deleted, i.e. it won't warn on:
void f() {
A a; // Not an issue.
}
The compiler can't detect this ODR violation because it's happening at link time, in different translation units. Some linkers can detect them. The way linking usually works is:
1. The linker loads all object files on the link line and builds a list of missing symbols.
2. While that list is not empty:
* Pick one missing symbol
* Using the index at the front of every static library on the link line,
determine if any static library contains that symbol
* Load the first object file from the first static library containing that symbol
* Update the list with newly defined and newly missing symbols from that object file
So if by bad luck the other Mock class is loaded first, ld might never realize that some other .o file defines that class too. OS X's ld can detect some more ODR violations if you pass -all_load, which causes it to load all .o files in all static libraries on the link line.
Nico