diff --git a/compilerplugins/clang/stringview.cxx b/compilerplugins/clang/stringview.cxx index 4043d7a67e60..b3a0323d2923 100644 --- a/compilerplugins/clang/stringview.cxx +++ b/compilerplugins/clang/stringview.cxx @@ -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(e)) { - handleCXXConstructExpr(e1); + if (e0 == subExpr) + { + handleCXXConstructExpr(e1); + } } else if (auto const e2 = dyn_cast(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; } diff --git a/compilerplugins/clang/test/stringview.cxx b/compilerplugins/clang/test/stringview.cxx index 63c8548a0b45..c03fbb84cb32 100644 --- a/compilerplugins/clang/test/stringview.cxx +++ b/compilerplugins/clang/test/stringview.cxx @@ -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::allowOUStringConcat && ToStringHelper::allowOUStringConcat, OUStringConcat{{ ?}}>' (aka 'rtl::OUStringConcat'), 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)