
Steven wrote:
The compiler may see that a member function of derived is being called with the pointer. Thus the pointer must really point to an object of the type derived. Thus it cannot point to b. Knowing that, the compiler is free to reorder the operations after inlining.
No way. The compiler doesn't reorder instructions from before and after an out of line function call because the compiler authors know that they can't guarantee correct behavior for exactly these types of reasons. If the function call is inline the compiler knows whether the pointer is the same or not and if it does not know it does not reorder the instructions because it *might* be the same. In the back-end the compiler doesn't have any idea what object type the pointer was anymore and certainly doesn't use that information to outsmart itself. The compiler is pessimistic and conservative in nature in the optimizations it makes. If compiler providers chose to do what you suggest they might then they would catch no end of grief until they rolled back the change. Luke