Lost virtual primary

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Consider this code: 

    class V{ 
    public: 

        virtual void f(){}; 
    }; 

    class A: public virtual V{ 
    }; 

Because V is nearly-empty, it is chosen as the primary base for A. This means that there is an entry in their shared vtable which points to V::F(). 

The call: 

    A *a; 
    a->f(); 

is translated to : 

    movq    -16(%rbp), %rax # a, tmp63 
    movq    (%rax), %rax    # a_2(D)->D.2214._vptr.V, D.2272 (1) 
    movq    (%rax), %rax    # *_3, D.2273 (2) 
    movq    -16(%rbp), %rdx # a, tmp64 
    movq    %rdx, %rdi  # tmp64, 
    call    *%rax   # D.2273 (3) 


Instructions (1), (2) and (3) show that this entry (in the shared vtable) is used for calls to f(). 

Now consider an addition to the previous code: 

    class B: public virtual V{ 
        void f(){ /*overidden */} 
    }; 

    class D: public B,public A { 
    }; 


In a D object, A has lost its primary base. Now the unique V object is stored inside B. How are calls to f made from a pointer to A? Does D create a thunk to replace the entry for f in A's vtable?

Using g++ -fdump-class-hierarchy, in the vtable for A-in-D, there is "0u" where the reference to f() should be.


Thank you!



[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux