The attached patch adds a warning when placing a call like:
func(*static_cast<mystruct*>(nullptr));
to the existing -Wnull-dereference warning.
The existing warning catches the case where the empty lvalue undergoes lvalue-to-rvalue conversion. The attached patch adds the check when it is used for copy initialization.
There's some significant opportunity for refactoring with the static CheckForNullPointerDereference function in SemaExpr.cpp (not to be confused with the one I'm adding to SemaInit.cpp). Also, I've chosen different warning text since all cases where the existing warning fires get compiled to nothing, while cases where this warning fires may generate object code (creating "null references" usually).
Please review!
Maybe "binding dereferenced null pointer [...]"?