improve defaultparams loplugin

to catch calling params with defaults like "= OUSString()"

Change-Id: Iad060e318ed492c22f8be44e326174fe6d28fff9
Reviewed-on: https://gerrit.libreoffice.org/22932
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Noel Grandin <noelgrandin@gmail.com>
This commit is contained in:
Noel Grandin
2016-03-05 18:03:25 +02:00
committed by Noel Grandin
parent 37a6bafea8
commit 70f87284c6
42 changed files with 107 additions and 119 deletions

View File

@@ -60,17 +60,40 @@ bool DefaultParams::VisitCallExpr(CallExpr * callExpr) {
if (!defaultArgExpr) {
break;
}
APSInt x1, x2;
if (!((defaultArgExpr->isNullPointerConstant(
compiler.getASTContext(), Expr::NPC_NeverValueDependent)
&& arg->isNullPointerConstant(
compiler.getASTContext(), Expr::NPC_NeverValueDependent))
|| (defaultArgExpr->EvaluateAsInt(x1, compiler.getASTContext())
&& arg->EvaluateAsInt(x2, compiler.getASTContext())
&& x1 == x2)))
bool found = false;
if (defaultArgExpr->isNullPointerConstant(compiler.getASTContext(), Expr::NPC_NeverValueDependent)
&& arg->isNullPointerConstant(compiler.getASTContext(), Expr::NPC_NeverValueDependent))
{
break;
found = true;
}
if (!found)
{
APSInt x1, x2;
if (defaultArgExpr->EvaluateAsInt(x1, compiler.getASTContext())
&& arg->EvaluateAsInt(x2, compiler.getASTContext())
&& x1 == x2)
{
found = true;
}
}
// catch params with defaults like "= OUString()"
if (!found
&& isa<MaterializeTemporaryExpr>(arg)
&& isa<MaterializeTemporaryExpr>(defaultArgExpr))
{
const CXXBindTemporaryExpr* strippedArg = dyn_cast_or_null<CXXBindTemporaryExpr>(arg->IgnoreParenCasts());
if (strippedArg && isa<CXXTemporaryObjectExpr>(strippedArg->getSubExpr())
&& dyn_cast<CXXTemporaryObjectExpr>(strippedArg->getSubExpr())->getNumArgs() == 0)
{
found = true;
}
}
if (!found)
break;
// Ignore CPPUNIT, it's macros contain some stuff that triggers us
StringRef aFileName = compiler.getSourceManager().getFilename(compiler.getSourceManager().getSpellingLoc(parmVarDecl->getLocStart()));
if (aFileName.find("include/cppunit") != std::string::npos)
break;
report(
DiagnosticsEngine::Warning,
"not necessary to pass this argument, it defaults to the same value",