diff options
author | Noel Grandin <noel@peralex.com> | 2016-03-05 18:03:25 +0200 |
---|---|---|
committer | Noel Grandin <noelgrandin@gmail.com> | 2016-03-07 05:57:17 +0000 |
commit | 70f87284c6ce77a49b1fac1431cea206f4b1dfa9 (patch) | |
tree | f979810ab0761169d094385940612aa1477056d6 /compilerplugins/clang/defaultparams.cxx | |
parent | 37a6bafea8416541d7d250d66a9e951400b197a3 (diff) |
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>
Diffstat (limited to 'compilerplugins/clang/defaultparams.cxx')
-rw-r--r-- | compilerplugins/clang/defaultparams.cxx | 41 |
1 files changed, 32 insertions, 9 deletions
diff --git a/compilerplugins/clang/defaultparams.cxx b/compilerplugins/clang/defaultparams.cxx index 3e5d5f826349..de030870a7f9 100644 --- a/compilerplugins/clang/defaultparams.cxx +++ b/compilerplugins/clang/defaultparams.cxx @@ -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", |