Use CTTI instead of RTTI where possible #792
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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:typeid
on a type which is known at compile-time (usually takinghash_code()
of the returnedstd::type_info
);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 providesctti::type_id<T>()
functions for compile-time type id, and alsoctti::type_id_t
type, similar tostd::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 includepolymorphic.hpp
or other related headers).