Under what conditions is the pure virtual method stub generated?

Viewed 372

I've read in many places (for example here) about people getting a "pure virtual method called" error and program crash at runtime. This answer says that

Most compilers assign such vtable entries to a stub which emits an error before aborting the program.

and this one even says that Itanium ABI specifies what that stub is.

The problem is: all my attempts to see this behaviour in action are caught by the compiler (GCC 6.4.1) at compile time as undefined references. For example, when calling a pure virtual function from a constructor of the abstract class, I get a warning

pure virtual ‘virtual int X::f()’ called from constructor

but at the same time simply no code at all is generated for X::f() so this is followed by

undefined reference to 'X::f()'

from the linker and the compilation fails. This seems a pretty foolproof way of preventing the error at runtime. In which situation would my compiler actually need to generate the aforementioned stub? Or has it gotten smart enough to detect all the possible pathological situations early enough?

1 Answers
Related