-
Notifications
You must be signed in to change notification settings - Fork 39
Allow compilation with -fno-rtti
#44
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Thanks for the suggestion. As you can see, I committed a different approach: We don't need RTTI anymore, but we can still demangle the types :) |
I saw some information about this but it seemed really complicated. I'm glad you did this because it will be helpful in my project with RTTI disabled. |
I never had a use-case for disabling RTTI, and I was under the impression that people that want/have to disable RTTI usually also can't use exceptions. So, first of all I'm happy it helped you, but I'm also curious: What environment allows exceptions but no RTTI? |
It's not that they're allowed or not per se. I just don't like the overhead that RTTI incurs. IIRC (and I'm not very sure because there's not much info), RTTI adds a vtable pointer to every object. I never use RTTI—in fact, I think it is squarely against proper OOP principles—so I have no reason to incur this overhead. |
The overhead of RTTI is generally very small, as it adds a pointer to the vtable if and only if the class already has a vtable. Classes without a vtable won't get one just because you enabled RTTI. There will be a typeid-structure (mostly the (mangled) name) for every class, but the compiler simply references this statically without dynamic lookup for non-virtual classes, so no vtable is needed/added in that case. And the vtable for virtual classes is shared between all objects of that class, meaning there is no per-object overhead added by RTTI, only a per-class overhead. |
Alright, that's good to know. I'm not sure why I couldn't find that information online. Seems like an implementation detail. On the other hand, does it increase the size of the binary? |
It does increase the binary size, but again it's not a big difference in my experience. I just ran a small experiment on a binary from the PEGTL: With RTTI, it was 179376 bytes long, with |
Interesting. Thanks. |
And there is a problem: So without RTTI-support the connection pool can not be used. II'll take care of it maybe tomorrow, for today I'm too tired. |
Forget it. I'll just enable RTTI. I thought this was much simpler than it is. I don't want to waste your time. |
https://en.cppreference.com/w/cpp/memory/shared_ptr/get_deleter Compiling the example with |
I'm confused. In https://en.cppreference.com/w/cpp/memory/shared_ptr, they say that the control block includes the deleter, but if that were true then why is RTTI required at all? Can't |
It's explained in the StackOverflow link I posted. It would be possible to implement get_deleter without RTTI, but it wasn't done and now it would break the ABI. |
Ah. Unfortunate. Anyway, I've enabled RTTI. I didn't used connection pool in the first place so there were no assertions that failed, but nonetheless I will enable it. That makes me curious though. Would it be possible to implement our own, similar but different version of shared_ptr, that doesn't use RTTI? |
That's possible, but I don't want to unnecessarily introduce types that resemble standard types. Remember the type gets exposed in our API, it's not just an implementation detail. I'll revert the changes to |
Using
typeid
doesn't seem to work even if the result can (and is) evaluated at compile-time. Specifically,typeid(int)
or similar results in a compilation error.Since this data is only used to make better error messages, and therefore is not crucial, replace the type string with "(no rtti)" when RTTI is disabled.