diff options
author | Noel Grandin <noel.grandin@collabora.co.uk> | 2017-01-27 16:09:54 +0200 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2017-01-28 09:22:55 +0000 |
commit | f1d83ac45f08270f7f2dd7128056effd0251dc5e (patch) | |
tree | 55d924eaa7f55627039d44458d869ef65130fdf8 /compilerplugins/clang | |
parent | 53d3755972bfd3bd2cd650edf91f1483038028c8 (diff) |
loplugin:stringconstant check for unnecessary OUString constructor..
..calls when creating exceptions
Change-Id: I3bc58a5aa4dc6f0508ecb88b3a843b96b8c7ebfe
Reviewed-on: https://gerrit.libreoffice.org/33617
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'compilerplugins/clang')
-rw-r--r-- | compilerplugins/clang/stringconstant.cxx | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/compilerplugins/clang/stringconstant.cxx b/compilerplugins/clang/stringconstant.cxx index 50b2a600b66b..8b00e84333e8 100644 --- a/compilerplugins/clang/stringconstant.cxx +++ b/compilerplugins/clang/stringconstant.cxx @@ -1053,6 +1053,38 @@ bool StringConstant::VisitCXXConstructExpr(CXXConstructExpr const * expr) { } return true; } + + + // Now check for calls to one of our exception classes where an unnecessary OUString + // constructor is used for the first parameter. + if (isInUnoIncludeFile(expr->getConstructor()->getCanonicalDecl())) { + return true; + } + if (!expr->getConstructor()->getParent()->getName().endswith("Exception")) { + return true; + } + if (expr->getNumArgs() == 0) { + return true; + } + MaterializeTemporaryExpr const * subExpr1 = dyn_cast<MaterializeTemporaryExpr>(expr->getArg(0)); + if (!subExpr1) { + return true; + } + if (!loplugin::TypeCheck(subExpr1->getType()).Class("OUString").Namespace("rtl").GlobalNamespace()) { + return true; + } + ImplicitCastExpr const * subExpr2 = dyn_cast<ImplicitCastExpr>(subExpr1->GetTemporaryExpr()); + if (!subExpr2) { + return true; + } + CXXFunctionalCastExpr const * subExpr3 = dyn_cast<CXXFunctionalCastExpr>(subExpr2->getSubExpr()); + if (!subExpr3) { + return true; + } + report(DiagnosticsEngine::Warning, + "no need to use an explicit OUString constructor here", + subExpr3->getLocStart()) + << subExpr3->getSourceRange(); return true; } |