diff options
author | Noel <noel.grandin@collabora.co.uk> | 2021-01-28 20:29:16 +0200 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2021-01-29 09:25:12 +0100 |
commit | 1250aecd71fabde4dba990bfceb61bbe8e06b8ea (patch) | |
tree | 3c42ffdf68b7e81aba29228631a8cd34e2f11830 /compilerplugins | |
parent | 4f3987e0b1a995431478769c898b5ef151745254 (diff) |
loplugin:stringviewparam extend to new..
O[U]StringBuffer methods
Change-Id: I0ffbc33d54ae7c98b5652434f3370ee4f819f6f4
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/110090
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'compilerplugins')
-rw-r--r-- | compilerplugins/clang/stringviewparam.cxx | 34 | ||||
-rw-r--r-- | compilerplugins/clang/test/stringviewparam.cxx | 8 |
2 files changed, 41 insertions, 1 deletions
diff --git a/compilerplugins/clang/stringviewparam.cxx b/compilerplugins/clang/stringviewparam.cxx index 86ee7c21b393..9182bf449bbe 100644 --- a/compilerplugins/clang/stringviewparam.cxx +++ b/compilerplugins/clang/stringviewparam.cxx @@ -65,6 +65,23 @@ StringType relevantStringType(QualType type) } } +bool isRelevantStringBufferType(QualType type) +{ + loplugin::TypeCheck const c(type); + if (c.Class("OStringBuffer").Namespace("rtl")) + { + return true; + } + else if (c.Class("OUStringBuffer").Namespace("rtl")) + { + return true; + } + else + { + return false; + } +} + bool relevantParmVarDecl(ParmVarDecl const* decl) { auto const t1 = decl->getType(); @@ -122,13 +139,28 @@ DeclRefExpr const* relevantImplicitCastExpr(ImplicitCastExpr const* expr) DeclRefExpr const* relevantCXXMemberCallExpr(CXXMemberCallExpr const* expr) { + auto const d = expr->getMethodDecl(); + if (isRelevantStringBufferType(compat::getObjectType(expr))) + { + if (auto const i = d->getIdentifier()) + { + auto const n = i->getName(); + if (n == "append" || n == "indexOf" || n == "lastIndexOf") + { + return relevantDeclRefExpr(expr->getArg(0)); + } + else if (n == "insert") + { + return relevantDeclRefExpr(expr->getArg(1)); + } + } + } StringType t = relevantStringType(compat::getObjectType(expr)); if (t == StringType::None) { return nullptr; } bool good = false; - auto const d = expr->getMethodDecl(); if (d->getOverloadedOperator() == OO_Subscript) { good = true; diff --git a/compilerplugins/clang/test/stringviewparam.cxx b/compilerplugins/clang/test/stringviewparam.cxx index 24dab18e0f9c..a9fcab3ac3a0 100644 --- a/compilerplugins/clang/test/stringviewparam.cxx +++ b/compilerplugins/clang/test/stringviewparam.cxx @@ -13,6 +13,7 @@ #include "rtl/string.hxx" #include "rtl/ustring.hxx" +#include "rtl/ustrbuf.hxx" #include "sal/types.h" void f1a(std::string_view); @@ -83,4 +84,11 @@ struct S10 } }; +// expected-error@+1 {{replace function parameter of type 'const rtl::OUString &' with 'std::u16string_view' [loplugin:stringviewparam]}} +void f11(const OUString& f11rString) +{ + OUStringBuffer buf; + buf.append(f11rString); +} + /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ |