Do not use static_cast when you cast from a basic class to a derived one. This may lead to undefined behavior. To handle the polymorphism, a virtual inheritance or a multiple inheritance case always use dynamic_cast instead.
The following short example shows the undefined behavior cases. This works with GCC, VC and online C++ shells:
Previously, comparing C++Builder classic and Clang compilers I regreted than CodeGuard tool doesn't work with Clang. Fortunately, there are other tools which can help you to profile program code and detect memory leaks. The Dataleaker is the one of these tools.