avoid crash on pointers to functions

Clang's dyn_cast<> crashes on NULL, and getParentFunctionOrMethod() is NULL
if the parameter is a part of a pointer-to-function declaration.

Change-Id: Iee9eef488746f9a46bc090df8d318f27ad65f0ef
This commit is contained in:
Luboš Luňák
2012-10-12 13:09:08 +02:00
parent 9c0304f5a7
commit d1eee073eb

View File

@@ -83,7 +83,7 @@ bool UnusedVariableCheck::VisitNamedDecl( NamedDecl* declaration )
return true; // unnamed parameter -> unused
// If this declaration does not have a body, then the parameter is indeed not used,
// so ignore.
if( const FunctionDecl* func = dyn_cast< FunctionDecl >( param->getParentFunctionOrMethod()))
if( const FunctionDecl* func = dyn_cast_or_null< FunctionDecl >( param->getParentFunctionOrMethod()))
if( !func->doesThisDeclarationHaveABody())
return true;
report( DiagnosticsEngine::Warning, "unused parameter %0 [loplugin]",