[cfe-dev] typeid and fno-rtti

Michel Morin mimomorin at gmail.com
Fri May 18 06:30:50 PDT 2012


I compiled the following code on clang (trunk) + libc++
with -fno-rtti compiler option:

    #include <typeinfo>

    int main (int argc, char* argv[])
    {
        bool x = (typeid(int) == typeid(int)); // Segmentation fault
        return 0;
    }

Then, I got segmentation fault at `bool x = (typeid(int) == typeid(int));`.
So I checked `&typeid(int)`, and it turned out to be a null pointer.

I suspect that, with -fno-rtti compiler option, `typeid(int)` becomes
something like `*static_cast<type_info*>(0)`.
If so, shouldn't we disable `typeid` operator when -fno-rtti is specified?
The current behavior of `typeid` with -fno-rtti option is useless.
(c.f. On gcc, the use of `typeid` requires RTTI.)


Regards,
Michel



More information about the cfe-dev mailing list