Now I know that there are no guarantees for inlining, but ...
Given the following:
struct Base { virtual int f() = 0; }; struct Derived : public Base { virtual int f() final override { return 42; } }; extern Base* b;
We have:
int main() { return static_cast<Derived*>(b)->f(); }
Compiles to:
main: movl $42, %eax ret
But...
int main() { return (static_cast<Derived*>(b)->*(&Derived::f))(); }
Compiles to:
main: pushl %ebp movl %esp, %ebp andl $-16, %esp subl $16, %esp movl b, %eax movl (%eax), %edx movl %eax, (%esp) call *(%edx) leave ret
Which is really sad.
Why is this PMF call not inline? PMF is a constant expression!
source share