Given:
struct T { virtual void foo() { } };
Using polymorphism (If you call foo() via pointer-to-T or reference-to-T )
T* ptr = get_ptr_somehow(); ptr->foo();
If the compiler knows that T is the only node in the inheritance tree, it can refuse virtual calls and potentially enable the function. However, this is an incredibly unlikely scenario, and I doubt it can even be detected. In all other cases, the attachment is impractical due to the sending of the execution time.
Static dispatch (if you call foo() on a standard object)
T obj; obj.foo();
In this case, the compiler knows that the dynamic type of obj is T , that it does not require a virtual send, and therefore can embed the function code if it wants to.
T* ptr = get_ptr_somehow(); ptr->T::foo();
In this case, the compiler does not know the dynamic type of obj , but it knows which function it will call, knows that it does not require a virtual send, and therefore can embed the function code if it wants to.
Lightness races in orbit
source share