summaryrefslogtreecommitdiff
path: root/compilerplugins
diff options
context:
space:
mode:
authorStephan Bergmann <sbergman@redhat.com>2021-10-01 09:09:45 +0200
committerStephan Bergmann <sbergman@redhat.com>2021-10-11 14:22:22 +0200
commit4f5b3e4bd53d6d61df1f65f496f7bc8dc525c8a1 (patch)
treee0ac44b8f22f944f3303bac8e494da41d6c7b164 /compilerplugins
parent5f84c44e3d5ff19b800b6358e61228546e318d4f (diff)
In O[U]StringBuffer, make string_view params replacements for OUString ones
...for LIBO_INTERNAL_ONLY, instead of having them as additional overloads. That way, loplugin:bufferadd and loplugin:stringviewparam found many further opportunities for simplification (all addressed here). Some notes: * There is no longer an implicit conversion from O[U]String to O[U]StringBuffer (as that goes via user-defined conversions through string_view now), which was most noticeable in copy initializations like OStringBuffer buf = someStr; that had to be changed to direct initialization, OStringBuffer buf(someStr); But then again, it wasn't too many places that were affected and I think we can live with that. * I made the O[U]StringBuffer ctors taking string_view non-explicit, mainly to get them in line with their counterparts taking O[U]String. * I added an OUStringBuffer::lastIndexOf string_view overload that was missing (relative to OUStringBuffer::indexOf). * loplugin:stringconstant needed some addition to keep the compilerplugins/clang/test/stringconstant.cxx checks related to OStringBuffer::append and OStringBuffer::insert working. * loplugin:stringviewparam no longer needs the special O[U]StringBuffer-related code that had been introduced in 1250aecd71fabde4dba990bfceb61bbe8e06b8ea "loplugin:stringviewparam extend to new.." Change-Id: Ib1bb8c4632d99b744e742605a9fef6eae959fd72 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/122904 Tested-by: Jenkins Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
Diffstat (limited to 'compilerplugins')
-rw-r--r--compilerplugins/clang/stringconstant.cxx6
-rw-r--r--compilerplugins/clang/stringviewparam.cxx34
2 files changed, 7 insertions, 33 deletions
diff --git a/compilerplugins/clang/stringconstant.cxx b/compilerplugins/clang/stringconstant.cxx
index 9f51dad4f148..5c237afa1924 100644
--- a/compilerplugins/clang/stringconstant.cxx
+++ b/compilerplugins/clang/stringconstant.cxx
@@ -94,6 +94,12 @@ CXXConstructExpr const * lookForCXXConstructExpr(Expr const * expr) {
if (auto e = dyn_cast<CXXBindTemporaryExpr>(expr)) {
expr = e->getSubExpr();
}
+ if (auto const e = dyn_cast<CXXMemberCallExpr>(expr)) {
+ // Look through OString::operator std::string_view:
+ if (auto const d = dyn_cast_or_null<CXXConversionDecl>(e->getCalleeDecl())) {
+ return lookForCXXConstructExpr(e->getImplicitObjectArgument()->IgnoreParenImpCasts());
+ }
+ }
return dyn_cast<CXXConstructExpr>(expr);
}
diff --git a/compilerplugins/clang/stringviewparam.cxx b/compilerplugins/clang/stringviewparam.cxx
index aa0899ca10a0..a500adf65d7c 100644
--- a/compilerplugins/clang/stringviewparam.cxx
+++ b/compilerplugins/clang/stringviewparam.cxx
@@ -65,23 +65,6 @@ 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();
@@ -139,28 +122,13 @@ 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;