summaryrefslogtreecommitdiff
path: root/compilerplugins
diff options
context:
space:
mode:
authorNoel <noelgrandin@gmail.com>2020-11-17 10:09:40 +0200
committerNoel Grandin <noel.grandin@collabora.co.uk>2020-11-17 12:12:03 +0100
commit0c7ac93103f69373a7e7639f4cf3ad464c0b727e (patch)
tree7d814c59be4e23b03cb266e3c797af0dcd927139 /compilerplugins
parent0979798658ff536defe537f57cc6b32278d32414 (diff)
loplugin:stringviewparam extend to constructors
Change-Id: Ia573921566ec6079b843cbcc0401d9d0f5c62089 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/105969 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'compilerplugins')
-rw-r--r--compilerplugins/clang/stringviewparam.cxx42
1 files changed, 41 insertions, 1 deletions
diff --git a/compilerplugins/clang/stringviewparam.cxx b/compilerplugins/clang/stringviewparam.cxx
index 76c34cd2adb9..040f8f63b502 100644
--- a/compilerplugins/clang/stringviewparam.cxx
+++ b/compilerplugins/clang/stringviewparam.cxx
@@ -222,7 +222,6 @@ public:
return ret;
}
- // TODO Need to duplicate this method for CXXConstructorDecl
bool TraverseCXXMethodDecl(CXXMethodDecl* decl)
{
if (ignoreLocation(decl))
@@ -264,6 +263,47 @@ public:
return ret;
}
+ bool TraverseCXXConstructorDecl(CXXConstructorDecl* decl)
+ {
+ if (ignoreLocation(decl))
+ {
+ return true;
+ }
+ if (!relevantFunctionDecl(decl))
+ {
+ return FunctionAddress::TraverseCXXConstructorDecl(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::TraverseCXXConstructorDecl(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))