summaryrefslogtreecommitdiff
path: root/compilerplugins
diff options
context:
space:
mode:
authorNoel <noelgrandin@gmail.com>2020-11-13 14:29:59 +0200
committerNoel Grandin <noel.grandin@collabora.co.uk>2020-11-17 09:57:35 +0100
commit8ef6067596cf4b2c52fbce94b44bf7af9fefa643 (patch)
treef4cca1a99ba97683b14fa6fe0f1f45f75bf855c2 /compilerplugins
parent75bada928cf08d2afc6efe52ba99b45088bc9eec (diff)
loplugin:stringviewparam check methods too
not just functions Change-Id: Icca295dd159002b428b73f2c95d40725434f04d9 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/105789 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'compilerplugins')
-rw-r--r--compilerplugins/clang/stringviewparam.cxx53
1 files changed, 53 insertions, 0 deletions
diff --git a/compilerplugins/clang/stringviewparam.cxx b/compilerplugins/clang/stringviewparam.cxx
index c0c720f06df5..76c34cd2adb9 100644
--- a/compilerplugins/clang/stringviewparam.cxx
+++ b/compilerplugins/clang/stringviewparam.cxx
@@ -158,6 +158,7 @@ DeclRefExpr const* relevantCXXMemberCallExpr(CXXMemberCallExpr const* expr)
DeclRefExpr const* relevantCXXOperatorCallExpr(CXXOperatorCallExpr const* expr)
{
+ // TODO OO_EqualEqual and similar
if (expr->getOperator() != OO_Subscript)
{
return nullptr;
@@ -221,6 +222,48 @@ public:
return ret;
}
+ // TODO Need to duplicate this method for CXXConstructorDecl
+ bool TraverseCXXMethodDecl(CXXMethodDecl* decl)
+ {
+ if (ignoreLocation(decl))
+ {
+ return true;
+ }
+ if (!relevantFunctionDecl(decl))
+ {
+ return FunctionAddress::TraverseCXXMethodDecl(decl);
+ }
+ auto const oldParams = currentParams_;
+ auto const n = decl->getNumParams();
+ for (unsigned i = 0; i != n; ++i)
+ {
+ auto const d = decl->getParamDecl(i);
+ if (relevantParmVarDecl(d))
+ {
+ currentParams_.insert(d);
+ }
+ }
+ auto const ret = FunctionAddress::TraverseCXXMethodDecl(decl);
+ if (ret)
+ {
+ for (unsigned i = 0; i != n; ++i)
+ {
+ auto const d1 = decl->getParamDecl(i);
+ if (currentParams_.find(d1) == currentParams_.end())
+ {
+ continue;
+ }
+ if (containsPreprocessingConditionalInclusion(decl->getSourceRange()))
+ {
+ break;
+ }
+ badParams_.push_back(d1);
+ }
+ }
+ currentParams_ = oldParams;
+ return ret;
+ }
+
bool TraverseImplicitCastExpr(ImplicitCastExpr* expr)
{
if (ignoreLocation(expr))
@@ -300,6 +343,12 @@ private:
{
return;
}
+ StringRef fn(handler.getMainFileName());
+ // leave the string QA tests alone
+ if (loplugin::hasPathnamePrefix(fn, SRCDIR "/sal/qa/"))
+ {
+ return;
+ }
if (!TraverseDecl(compiler.getASTContext().getTranslationUnitDecl()))
{
return;
@@ -346,6 +395,10 @@ private:
return false;
}
}
+ if (decl->isOverloadedOperator()) // e.g. operator()(const OUString&, const OUString&)
+ {
+ return false;
+ }
if (decl->isFunctionTemplateSpecialization())
{
return false;