Skip to content
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

Use CTTI instead of RTTI where possible #792

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

sharkov63
Copy link

In some projects we are required to use -fno-rtti option, which disables RTTI (run-time type information). cereal uses typeid operator, which requires RTTI, in the following two scenarios:

  1. using typeid on a type which is known at compile-time (usually taking hash_code() of the returned std::type_info);
  2. using typeid in order to support serialization of polymorphic types (i.e. here types are not known at compile time), see polymorphic.hpp.

While usage in the scenario 2 is required to serialize polymorphic types, we don't need RTTI at all in scenario 1.

This PR replaced all usages of typeid having a compile-time known type with methods from an external library ctti (open source, MIT license) - this library provides ctti::type_id<T>() functions for compile-time type id, and also ctti::type_id_t type, similar to std::type_info.

With this change one can use cereal with -fno-rtti flag, in case when one does not serialize any polymorphic types (i.e. does not include polymorphic.hpp or other related headers).

@sharkov63 sharkov63 marked this pull request as draft June 30, 2023 12:05
@sharkov63
Copy link
Author

Converted to draft because there is at least another instance of using typeid with compile-time known type: see util.hpp

@sharkov63 sharkov63 marked this pull request as ready for review July 2, 2023 15:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant