Turn off checks in dynamic_cast of reference types in release builds

Erik esigra@gmail.com
Wed Sep 30 06:50:00 GMT 2009


Bjarne Stroustrup wrote in his book The C++ programming language that;
while a dynamic_cast to a pointer type is a question (the result should
be checked), a dynamic_cast to a reference type is like an assertion. We
have followed this advice in our project. Now we need to disable these
assertions in release builds, so that dynamic_cast<Derived &>(base) is
just as efficient as static_cast<Derived &>(base). But I do not know how
to tell this to the compiler. I only found some other checks in gcc,
that can be disabled for release builds, such as the Ada checks (-gnatp).

Or is the feature that I need missing in gcc? Maybe I have to use one of
the many hacks called down_cast, safe_cast and so on, that can be found
on the web? Like this one:
http://smolsky.net/index.php/2009/09/14/down_cast-v2
If so, which of those hacks is the correct one that should be used?



More information about the Gcc-help mailing list