Now, I know 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 that:
int main() {
return static_cast<Derived*>(b)->f();
}
Compiles down to:
main:
movl $42, %eax
ret
Yet...
int main() {
return (static_cast<Derived*>(b)->*(&Derived::f))();
}
Compiles down 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 saddening.
Why is that call to PMF not being inlined? The PMF is a constant expression!