diff options
Diffstat (limited to 'compilerplugins/clang/redundantfcast.cxx')
-rw-r--r-- | compilerplugins/clang/redundantfcast.cxx | 54 |
1 files changed, 32 insertions, 22 deletions
diff --git a/compilerplugins/clang/redundantfcast.cxx b/compilerplugins/clang/redundantfcast.cxx index 67ff2c56edef..3a4dea0fd591 100644 --- a/compilerplugins/clang/redundantfcast.cxx +++ b/compilerplugins/clang/redundantfcast.cxx @@ -16,6 +16,8 @@ #include <unordered_set> #include <vector> +#include "config_clang.h" + namespace { class RedundantFCast final : public loplugin::FilteringPlugin<RedundantFCast> @@ -42,7 +44,7 @@ public: expr = cxxConstructExpr->getArg(0); } if (auto materializeTemporaryExpr = dyn_cast<MaterializeTemporaryExpr>(expr)) - expr = compat::getSubExpr(materializeTemporaryExpr); + expr = materializeTemporaryExpr->getSubExpr(); auto cxxFunctionalCastExpr = dyn_cast<CXXFunctionalCastExpr>(expr); if (!cxxFunctionalCastExpr) return true; @@ -56,9 +58,15 @@ public: return true; } if (m_Seen.insert(cxxFunctionalCastExpr->getExprLoc()).second) + { + if (suppressWarningAt(cxxFunctionalCastExpr->getBeginLoc())) + { + return true; + } report(DiagnosticsEngine::Warning, "redundant functional cast from %0 to %1", cxxFunctionalCastExpr->getExprLoc()) << t2 << t1 << cxxFunctionalCastExpr->getSourceRange(); + } return true; } @@ -94,7 +102,7 @@ public: if (!materializeTemporaryExpr) continue; auto functionalCast = dyn_cast<CXXFunctionalCastExpr>( - compat::getSubExpr(materializeTemporaryExpr)->IgnoreImpCasts()); + materializeTemporaryExpr->getSubExpr()->IgnoreImpCasts()); if (!functionalCast) continue; auto const t1 = functionalCast->getTypeAsWritten(); @@ -174,6 +182,10 @@ public: if (m_Seen.insert(arg->getExprLoc()).second) { + if (suppressWarningAt(arg->getBeginLoc())) + { + continue; + } report(DiagnosticsEngine::Warning, "redundant functional cast from %0 to %1 in construct expression", arg->getExprLoc()) @@ -220,18 +232,19 @@ public: { return false; } - if (t2->getNumArgs() != 1) + auto const args = t2->template_arguments(); + if (args.size() != 1) { if (isDebugMode()) { report(DiagnosticsEngine::Fatal, "TODO: unexpected std::function with %0 template arguments", expr->getExprLoc()) - << t2->getNumArgs() << expr->getSourceRange(); + << compat::diagnosticSize(args.size()) << expr->getSourceRange(); } return false; } - if (t2->getArg(0).getKind() != TemplateArgument::Type) + if (args[0].getKind() != TemplateArgument::Type) { if (isDebugMode()) { @@ -242,7 +255,7 @@ public: } return false; } - target = t2->getArg(0).getAsType(); + target = args[0].getAsType(); } else { @@ -277,10 +290,15 @@ public: if (ignoreLocation(expr)) return true; // specifying the name for an init-list is necessary sometimes - if (isa<InitListExpr>(compat::IgnoreParenImplicit(expr->getSubExpr()))) + auto const e = compat::IgnoreParenImplicit(expr->getSubExpr()); + if (isa<InitListExpr>(e)) + return true; + if (isa<CXXStdInitializerListExpr>(e)) return true; - if (isa<CXXStdInitializerListExpr>(compat::IgnoreParenImplicit(expr->getSubExpr()))) +#if CLANG_VERSION >= 160000 + if (isa<CXXParenListInitExpr>(e)) return true; +#endif auto const t1 = expr->getTypeAsWritten(); auto const t2 = compat::getSubExprAsWritten(expr)->getType(); if (!(t1.getCanonicalType().getTypePtr() == t2.getCanonicalType().getTypePtr() @@ -310,9 +328,15 @@ public: return true; if (m_Seen.insert(expr->getExprLoc()).second) + { + if (suppressWarningAt(expr->getBeginLoc())) + { + return true; + } report(DiagnosticsEngine::Warning, "redundant functional cast from %0 to %1", expr->getExprLoc()) << t2 << t1 << expr->getSourceRange(); + } return true; } @@ -320,20 +344,6 @@ public: { if (!compiler.getLangOpts().CPlusPlus) return false; - std::string fn = handler.getMainFileName().str(); - loplugin::normalizeDotDotInFilePath(fn); - // necessary on some other platforms - if (fn == SRCDIR "/sal/osl/unx/socket.cxx") - return false; - // compile-time check of constant - if (fn == SRCDIR "/bridges/source/jni_uno/jni_bridge.cxx") - return false; - // TODO constructing a temporary to pass to a && param - if (fn == SRCDIR "/sc/source/ui/view/viewfunc.cxx") - return false; - // tdf#145203: FIREBIRD cannot create a table - if (fn == SRCDIR "/connectivity/source/drivers/firebird/DatabaseMetaData.cxx") - return false; return true; } |