What can make C++ RTTI undesirable to use?

后端 未结 4 1593
梦毁少年i
梦毁少年i 2020-12-02 07:25

Looking at the LLVM documentation, they mention that they use \"a custom form of RTTI\", and this is the reason they have isa<>, cast<>

4条回答
  •  时光说笑
    2020-12-02 08:05

    The LLVM coding standards seem to answer this question fairly well:

    In an effort to reduce code and executable size, LLVM does not use RTTI (e.g. dynamic_cast<>) or exceptions. These two language features violate the general C++ principle of "you only pay for what you use", causing executable bloat even if exceptions are never used in the code base, or if RTTI is never used for a class. Because of this, we turn them off globally in the code.

    That said, LLVM does make extensive use of a hand-rolled form of RTTI that use templates like isa<>, cast<>, and dyn_cast<>. This form of RTTI is opt-in and can be added to any class. It is also substantially more efficient than dynamic_cast<>.

提交回复
热议问题