I ran cppcheck over some code to look for possible runtime errors. And it is reporting a possible null pointer dereference with the following situation:
Foo* x = ... //defined somewhere
...
Foo* y(x); //possible null pointer dereference.
Edit: Better example
for( int i = 0; i < N; i++ )
{
Foo* x( ArrayOfObjsContainingFooPtr[i].FooPtr ); // line 3
if( !x ) // line 4
continue;
}
Error message from cppcheck:
[C:\file.cpp:3]: (error) Possible null pointer dereference: x - otherwise it is redundant to check if x is null at line 4
But I don't see how this is possible.