SUSE / clang-extract

A tool to extract code content from source files using the clang and LLVM infrastructure.
Other
16 stars 2 forks source link

Replace dynamic_cast with dyn_cast in accordance with Issue #87 #90

Closed jh991205 closed 4 months ago

jh991205 commented 4 months ago

This commit addresses Issue #87, where it was noted that Clang, when compiled without RTTI (Run-Time Type Information), causes dynamic_cast to fail. This failure occurs because dynamic_cast relies on RTTI to safely cast pointers or references across an inheritance hierarchy. In environments where RTTI is disabled, dynamic_cast cannot perform these operations, leading to potential runtime errors.

Replacing dynamic_cast with Clang's dyn_cast<> provides a more reliable alternative in such scenarios. dyn_cast<> performs a similar operation but does not rely on RTTI, making it suitable for use in environments where RTTI is unavailable. It is important to note that dyn_cast<> will return nullptr if the cast is unsuccessful, which should be handled appropriately in the code to avoid dereferencing null pointers.