https://gcc.gnu.org/bugzilla/show_bug.cgi?id=115413

--- Comment #1 from user202729 <user202729 at protonmail dot com> ---
In practice, one way to implement this is to rewrite all instances of

    typeid(a) == typeid(b)

into roughly the following (assuming the virtual pointer table has exactly 1
pointer to function)

    typeid(a) == typeid(b) && (a._vptr[0] == b._vptr[0] ? true :
__builtin_unreachable())

I think this would work fine, except if the user wants to use the gcc extension
https://gcc.gnu.org/onlinedocs/gcc/Bound-member-functions.html to print out the
value of the function pointer.

On that note, would it be desirable to devirtualize call that explicitly
extracts the function pointer?

    #include<typeinfo>

    struct A{
        virtual void f(int);
    };

    void f(A& b){
        if (typeid(b) == typeid(A))
            ((void (*)(A*, int)) (b.*&A::f)) (&b, 1); // devirtualize this?
    }

It is feasible someone would want to optimize this (because after all, the
original purpose of the gcc extension is to manually optimize the code);
however, it would be extremely confusing if the user were to e.g. print out the
value of the function pointer before calling it in order to e.g. set a
breakpoint at the address in gdb.

Reply via email to