Virtual Optimisation

In terms of optimisations, are empty virtual (non-pure) functions subject to optimisation? Let me make things clear with a bit of example code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
struct B
{
    virtual void Function( )
    {
    }
};

struct C
{
    virtual void Function( )
    {
        // Modify something...
    }
};

Notice how B::Function( ) is empty but C::Function( ) is not. If I call B::Function( ), will the compiler realise that the function call is empty and optimise it away? Or will the compiler call it anyway?

Thanks.
If I call B::Function( ), will the compiler realise that the function call is empty and optimise it away?
If compiler would be able to perform devirtualization and prove that it is really B::Function( ) is being called, or you will just call B::Function( ) explicitely, then yes, I would expect it to optimise away call.
Brilliant. Thank you, MiiNiPaa.
The compiler might or not devirtualize methods , but it mostly depends on your design.
Topic archived. No new replies allowed.