Am 16.08.2010 um 17:00 schrieb pulkomandy: > On Mon, Aug 16, 2010 at 04:53:20PM +0200, Michael Pfeiffer wrote: > static_cast will never return NULL. That's the problem and may hide a future bug if the code ever changes. > But you have to be sure there are > only PrinterItem in the list or the object returned will be invalid, or > there will be a runtime exception. In this case I don't think this will > ever happen unless someone really mess with the code, so the check isn't > useful. You cannot know that it won't ever change. It is much safer to have runtime checks in source code than to rely on the knowledge of a human about the code. > Using dynamic_cast is not useful in these cases and is also slower. Being slower does not matter in this case as this is no time critical code. > And doing an assert would be a bit silly. If the only way to avoid a crash > is to crash before it, why bother adding code for that ? Using an assertion ensures the crash to happen near to cause of the problem. I wouldn't call that silly. Actually, I don't know if using a NULL pointer leads always immediately to a crash. When I wrote the code I assumed that that would happen. But since Coverty complains about it there should be a solution applied that does not make the code unsafer. Any other opinions? Bye, Michael