From 9a1e6d916eff1236cc1be2056c91e56018a482bf Mon Sep 17 00:00:00 2001 From: Noel Grandin Date: Fri, 4 Mar 2016 09:24:48 +0200 Subject: loplugin:unuseddefaultparam in sfx2 and fix an issue with calls to templated methods in the plugin Change-Id: I9c9537a0690ff671286c007846d5f4cfb7d2982b --- compilerplugins/clang/unuseddefaultparams.cxx | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) (limited to 'compilerplugins') diff --git a/compilerplugins/clang/unuseddefaultparams.cxx b/compilerplugins/clang/unuseddefaultparams.cxx index a194be26e726..e8b99d37e679 100644 --- a/compilerplugins/clang/unuseddefaultparams.cxx +++ b/compilerplugins/clang/unuseddefaultparams.cxx @@ -129,10 +129,17 @@ bool UnusedDefaultParams::VisitCallExpr(CallExpr * callExpr) { if (ignoreLocation(callExpr)) { return true; } - if (callExpr->getDirectCallee() == nullptr) { + const FunctionDecl* functionDecl; + if (isa(callExpr)) { + functionDecl = dyn_cast(callExpr)->getMethodDecl(); + } + else { + functionDecl = callExpr->getDirectCallee(); + } + if (functionDecl == nullptr) { return true; } - const FunctionDecl* functionDecl = callExpr->getDirectCallee()->getCanonicalDecl(); + functionDecl = functionDecl->getCanonicalDecl(); // method overrides don't always specify the same default params (althogh they probably should) // so we need to work our way up to the root method while (isa(functionDecl)) { @@ -141,6 +148,16 @@ bool UnusedDefaultParams::VisitCallExpr(CallExpr * callExpr) { break; functionDecl = *methodDecl->begin_overridden_methods(); } + // work our way back to the root definition for template methods + if (functionDecl->getInstantiatedFromMemberFunction()) + functionDecl = functionDecl->getInstantiatedFromMemberFunction(); + else if (functionDecl->getClassScopeSpecializationPattern()) + functionDecl = functionDecl->getClassScopeSpecializationPattern(); +// workaround clang-3.5 issue +#if CLANG_VERSION >= 30600 + else if (functionDecl->getTemplateInstantiationPattern()) + functionDecl = functionDecl->getTemplateInstantiationPattern(); +#endif auto n = functionDecl->getNumParams(); if (n == 0 || !functionDecl->getParamDecl(n - 1)->hasDefaultArg()) { return true; -- cgit