From ade276923280230a93d3fbd44b7066b2e9d5f93b Mon Sep 17 00:00:00 2001 From: Noel Grandin Date: Tue, 26 Sep 2017 09:53:13 +0200 Subject: improve unnecessarycatchthrow plugin it is not legal to eliminate a catch/re-throw where the re-throw expliciting mentions the exception variable and the exception variable is a non-final class Change-Id: I7fd88b0d004d2efa66aef2c0876e07f203da3c28 Reviewed-on: https://gerrit.libreoffice.org/42782 Reviewed-by: Noel Grandin Tested-by: Noel Grandin --- compilerplugins/clang/unnecessarycatchthrow.cxx | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'compilerplugins/clang/unnecessarycatchthrow.cxx') diff --git a/compilerplugins/clang/unnecessarycatchthrow.cxx b/compilerplugins/clang/unnecessarycatchthrow.cxx index c69713799a82..948394e9e37a 100644 --- a/compilerplugins/clang/unnecessarycatchthrow.cxx +++ b/compilerplugins/clang/unnecessarycatchthrow.cxx @@ -58,6 +58,15 @@ bool UnnecessaryCatchThrow::VisitCXXTryStmt(CXXTryStmt const * tryStmt) auto subExpr = throwExpr->getSubExpr(); if (subExpr) { + if (auto cxxConstructExpr = dyn_cast(subExpr)) { + if (!cxxConstructExpr->getConstructor()->isCopyConstructor()) + return true; + if (!cxxConstructExpr->getConstructor()->getParent()->hasAttr()) + return true; + if (cxxConstructExpr->getNumArgs() != 1) + return true; + subExpr = cxxConstructExpr->getArg(0); + } auto declRefExpr = dyn_cast(subExpr->IgnoreImpCasts()); if (!declRefExpr) return true; -- cgit