From 0c7ac93103f69373a7e7639f4cf3ad464c0b727e Mon Sep 17 00:00:00 2001 From: Noel Date: Tue, 17 Nov 2020 10:09:40 +0200 Subject: loplugin:stringviewparam extend to constructors Change-Id: Ia573921566ec6079b843cbcc0401d9d0f5c62089 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/105969 Tested-by: Jenkins Reviewed-by: Noel Grandin --- compilerplugins/clang/stringviewparam.cxx | 42 ++++++++++++++++++++++++++++++- 1 file changed, 41 insertions(+), 1 deletion(-) (limited to 'compilerplugins') 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)) -- cgit