I was very surprised to observe the code generated by visual C ++ (VS2017 RC) to see dynamic branching (virtual call) in simple cases.
So, I tried the following code with the compiler explorer:
struct Base { virtual void foo() = 0; }; struct Impl : Base { void foo() override; }; Impl g_impl; void globalCall() { g_impl.foo(); } void localCall() { Impl i; i.foo(); } void tempCall() { Impl().foo();
Compiler Explorer Link: https://godbolt.org/g/RmUku2
In temporary and membership cases, it does not seem to be devirtualization. Is this the quality of the compilerβs execution, or are there justified reasons for such a result?
source share