Avoid unhelpful loplugin:stringview from implicit conversions

> compilerplugins/clang/test/stringview.cxx Line 149: instead of an 'rtl::OString' constructed from a 'const rtl::OStringLiteral<4>', pass a 'std::string_view' [loplugin:stringview]
> compilerplugins/clang/test/stringview.cxx Line 150: instead of an 'rtl::OUString' constructed from a 'const rtl::OUStringLiteral<4>', pass a 'std::u16string_view' [loplugin:stringview]

(see the discussion at <https://gerrit.libreoffice.org/c/core/+/124950>
"operator==(OString, OStringLiteral)")

Change-Id: I5481bef8b8bad7bf9bdf4fff29161f0809051f2b
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/124990
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
This commit is contained in:
Stephan Bergmann 2021-11-10 16:26:05 +01:00 committed by Noel Grandin
parent 48ae3cc1af
commit 0ac45af39c
2 changed files with 19 additions and 12 deletions

View file

@ -75,18 +75,18 @@ bool StringView::VisitCXXOperatorCallExpr(CXXOperatorCallExpr const* cxxOperator
auto op = cxxOperatorCallExpr->getOperator();
if (op == OO_Plus && cxxOperatorCallExpr->getNumArgs() == 2)
{
handleSubExprThatCouldBeView(compat::IgnoreImplicit(cxxOperatorCallExpr->getArg(0)));
handleSubExprThatCouldBeView(compat::IgnoreImplicit(cxxOperatorCallExpr->getArg(1)));
handleSubExprThatCouldBeView(cxxOperatorCallExpr->getArg(0));
handleSubExprThatCouldBeView(cxxOperatorCallExpr->getArg(1));
}
if (compat::isComparisonOp(cxxOperatorCallExpr))
{
handleSubExprThatCouldBeView(compat::IgnoreImplicit(cxxOperatorCallExpr->getArg(0)));
handleSubExprThatCouldBeView(compat::IgnoreImplicit(cxxOperatorCallExpr->getArg(1)));
handleSubExprThatCouldBeView(cxxOperatorCallExpr->getArg(0));
handleSubExprThatCouldBeView(cxxOperatorCallExpr->getArg(1));
}
else if (op == OO_PlusEqual)
handleSubExprThatCouldBeView(compat::IgnoreImplicit(cxxOperatorCallExpr->getArg(1)));
handleSubExprThatCouldBeView(cxxOperatorCallExpr->getArg(1));
else if (op == OO_Subscript)
handleSubExprThatCouldBeView(compat::IgnoreImplicit(cxxOperatorCallExpr->getArg(0)));
handleSubExprThatCouldBeView(cxxOperatorCallExpr->getArg(0));
else if (op == OO_Equal)
{
if (loplugin::TypeCheck(cxxOperatorCallExpr->getType())
@ -98,7 +98,7 @@ bool StringView::VisitCXXOperatorCallExpr(CXXOperatorCallExpr const* cxxOperator
.Namespace("rtl")
.GlobalNamespace())
{
handleSubExprThatCouldBeView(compat::IgnoreImplicit(cxxOperatorCallExpr->getArg(1)));
handleSubExprThatCouldBeView(cxxOperatorCallExpr->getArg(1));
}
}
return true;
@ -130,7 +130,8 @@ bool StringView::VisitImplicitCastExpr(ImplicitCastExpr const* expr)
void StringView::handleSubExprThatCouldBeView(Expr const* subExpr)
{
auto const e = subExpr->IgnoreParens();
auto const e0 = compat::IgnoreImplicit(subExpr);
auto const e = e0->IgnoreParens();
auto const tc = loplugin::TypeCheck(e->getType());
if (!(tc.Class("OString").Namespace("rtl").GlobalNamespace()
|| tc.Class("OUString").Namespace("rtl").GlobalNamespace()))
@ -139,7 +140,10 @@ void StringView::handleSubExprThatCouldBeView(Expr const* subExpr)
}
if (auto const e1 = dyn_cast<CXXConstructExpr>(e))
{
handleCXXConstructExpr(e1);
if (e0 == subExpr)
{
handleCXXConstructExpr(e1);
}
}
else if (auto const e2 = dyn_cast<CXXFunctionalCastExpr>(e))
{
@ -301,11 +305,11 @@ bool StringView::VisitCXXMemberCallExpr(CXXMemberCallExpr const* expr)
auto const dc = loplugin::DeclCheck(expr->getMethodDecl());
if (dc.Function("append") || dc.Function("indexOf") || dc.Function("lastIndexOf"))
{
handleSubExprThatCouldBeView(compat::IgnoreImplicit(expr->getArg(0)));
handleSubExprThatCouldBeView(expr->getArg(0));
}
else if (dc.Function("insert"))
{
handleSubExprThatCouldBeView(compat::IgnoreImplicit(expr->getArg(1)));
handleSubExprThatCouldBeView(expr->getArg(1));
}
return true;
}
@ -330,7 +334,7 @@ bool StringView::VisitCXXConstructExpr(CXXConstructExpr const* expr)
return true;
}
if (expr->getNumArgs() > 0)
handleSubExprThatCouldBeView(compat::IgnoreImplicit(expr->getArg(0)));
handleSubExprThatCouldBeView(expr->getArg(0));
return true;
}

View file

@ -145,6 +145,9 @@ void f5(char const* s1, sal_Int32 n1, char16_t const* s2, sal_Int32 n2, OString
call_view(OUString(OUString::number(0)));
// expected-error-re@+1 {{instead of an 'rtl::OUString' constructed from a 'typename std::enable_if_t<ToStringHelper<OUString>::allowOUStringConcat && ToStringHelper<OUString>::allowOUStringConcat, OUStringConcat<OUString, OUString>{{ ?}}>' (aka 'rtl::OUStringConcat<rtl::OUString, rtl::OUString>'), pass a 'std::u16string_view' via 'rtl::OUStringConcatenation' [loplugin:stringview]}}
call_view(OUString(s4 + s4));
(void)(s3 == l1);
(void)(s4 == l2);
}
void f5(OUString s)