Fix loplugin:unusedvariablecheck

...on macOS, where it started to cause false positives like

> vcl/inc/osx/a11ywrapper.h:89:98: error: unused parameter 'anAccessibleContext' [loplugin:unusedvariablecheck]
> -(id)initWithAccessibleContext: (css::uno::Reference < css::accessibility::XAccessibleContext >) anAccessibleContext;
>                                                                                                  ^

after a214369f14 "loplugin:unusedvariablecheck
improve"

Change-Id: I450df3a6d768b4452d0975b5920ea0b3ce53ce13
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/127220
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
This commit is contained in:
Stephan Bergmann 2021-12-21 11:18:36 +01:00
parent 8d7e266943
commit b927eaa6db

View file

@ -80,9 +80,15 @@ bool UnusedVariableCheck::VisitVarDecl( const VarDecl* var )
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_or_null< FunctionDecl >( param->getParentFunctionOrMethod()))
auto const parent = param->getParentFunctionOrMethod();
if( const FunctionDecl* func = dyn_cast_or_null< FunctionDecl >( parent))
if( !func->doesThisDeclarationHaveABody() || func->getBody() == nullptr)
return true;
if (auto const d = dyn_cast_or_null<ObjCMethodDecl>(parent)) {
if (!d->hasBody()) {
return true;
}
}
report( DiagnosticsEngine::Warning, "unused parameter %0",
var->getLocation()) << var->getDeclName();
}