Well, sort of - my question is, since the destructor has to be virtual in order to be marked final (you get an error otherwise), does this cause virtual function overhead anywhere, or add a vtable?
As you want to always have virtual destructor if your class might be refernced by pointer to base class, you rerely will have to worry about that
In case when you only might want for destructor to be virtual final to prevent inheritance, this is a tricky question. Basically it should generate a vtable and store a pointer to it in class, adding overhead in virtual destructor call. However overhead is minimal and I hope destructor is not the most used function in your class.
I can imagine that if only virtual function is final destructor and your class isn't inherited from other, compiler will deduce that virtualness of destructor does not matter and will generate code as it wasn't virtual.
On a simple test case gcc had generated exactly same assembly code in both virtual and non-virtual case on -O2 (and had generated different code without optimizations). However it is too simple case to be sure.
So if RTTI were disabled (-fno-rtti) then in this case it would not generate the vtable? I assume that the compiler is smart, just wanted to be sure since this is a relatively new C++11 feature involved.
AFAIK, at best it can elide the code to initialize the vtable pointer during construction. But to conform to C++ semantics, A is not a pod, A is not a standard-layout-type, A is not trivially-constructible etc.
If it elided everything, A would become a pod.
The "as-if" rule always applies. It is adequate that the observable behaviour of A was as if it is not a pod, it is not a standard-layout-type, it is not trivially-constructible etc.
Compiler writers tend to invest in optimizing commonly used constructs, and ignore the rarely encountered ones. The extremely rare "polymorphic type with no base class and no derived classes" is not going to engage their attention. The earlier optimization arose from the more general, fairly often encountered in practise, "optimize away the overhead of runtime dispach, if by static analysis, the function to be called can be determined at compile time".