[Libreoffice-commits] core.git: compilerplugins/clang
Stephan Bergmann (via logerrit)
logerrit at kemper.freedesktop.org
Tue Oct 15 20:25:20 UTC 2019
compilerplugins/clang/stringadd.cxx | 16 ++++++++++------
compilerplugins/clang/test/stringadd.cxx | 6 +++---
2 files changed, 13 insertions(+), 9 deletions(-)
New commits:
commit 033ecf0127b0e232c45e727988c6d446c7ea5964
Author: Stephan Bergmann <sbergman at redhat.com>
AuthorDate: Tue Oct 15 16:45:57 2019 +0200
Commit: Stephan Bergmann <sbergman at redhat.com>
CommitDate: Tue Oct 15 22:24:03 2019 +0200
Improve loplugin:stringadd diagnostics
Change-Id: I8b87c4e56f10417acd538b765b3f8e4cc6e12fb9
Reviewed-on: https://gerrit.libreoffice.org/80844
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann <sbergman at redhat.com>
diff --git a/compilerplugins/clang/stringadd.cxx b/compilerplugins/clang/stringadd.cxx
index 764ef25adecc..7ae30922d5c8 100644
--- a/compilerplugins/clang/stringadd.cxx
+++ b/compilerplugins/clang/stringadd.cxx
@@ -193,8 +193,9 @@ bool StringAdd::VisitCXXOperatorCallExpr(CXXOperatorCallExpr const* operatorCall
&& !tc.Class("OString").Namespace("rtl").GlobalNamespace())
return true;
- auto check = [this, &tc](const Expr* expr) {
- auto const e = dyn_cast<CXXFunctionalCastExpr>(expr->IgnoreParenImpCasts());
+ auto check = [operatorCall, this, &tc](unsigned arg) {
+ auto const e
+ = dyn_cast<CXXFunctionalCastExpr>(operatorCall->getArg(arg)->IgnoreParenImpCasts());
if (e == nullptr)
return;
auto tc3 = loplugin::TypeCheck(e->getType());
@@ -210,13 +211,16 @@ bool StringAdd::VisitCXXOperatorCallExpr(CXXOperatorCallExpr const* operatorCall
cxxConstruct->getConstructor()->getParamDecl(0)->getType())
.Char())
return;
- report(DiagnosticsEngine::Warning, "avoid constructing temporary object from %0 during +",
+ report(DiagnosticsEngine::Warning,
+ ("avoid constructing %0 from %1 on %select{L|R}2HS of + (where %select{R|L}2HS is of"
+ " type %3)"),
compat::getBeginLoc(e))
- << e->getSubExprAsWritten()->getType() << e->getSourceRange();
+ << e->getType().getLocalUnqualifiedType() << e->getSubExprAsWritten()->getType() << arg
+ << operatorCall->getArg(1 - arg)->IgnoreImpCasts()->getType() << e->getSourceRange();
};
- check(operatorCall->getArg(0));
- check(operatorCall->getArg(1));
+ check(0);
+ check(1);
return true;
}
diff --git a/compilerplugins/clang/test/stringadd.cxx b/compilerplugins/clang/test/stringadd.cxx
index fc06e5e33b5c..c4fe15b16d68 100644
--- a/compilerplugins/clang/test/stringadd.cxx
+++ b/compilerplugins/clang/test/stringadd.cxx
@@ -163,9 +163,9 @@ void f1(OUString s, OUString t, int i, const char* pChar)
{
// no warning expected
t = t + "xxx";
- // expected-error at +1 {{avoid constructing temporary object from 'const char [4]' during + [loplugin:stringadd]}}
+ // expected-error at +1 {{avoid constructing 'rtl::OUString' from 'const char [4]' on RHS of + (where LHS is of type 'rtl::OUString') [loplugin:stringadd]}}
s = s + OUString("xxx");
- // expected-error at +1 {{avoid constructing temporary object from 'const rtl::OUString' during + [loplugin:stringadd]}}
+ // expected-error at +1 {{avoid constructing 'rtl::OUString' from 'const rtl::OUString' on RHS of + (where LHS is of type 'rtl::OUString') [loplugin:stringadd]}}
s = s + OUString(getByRef());
// no warning expected
@@ -183,7 +183,7 @@ void f1(OUString s, OUString t, int i, const char* pChar)
void f2(char ch)
{
OString s;
- // expected-error at +1 {{avoid constructing temporary object from 'const char [4]' during + [loplugin:stringadd]}}
+ // expected-error at +1 {{avoid constructing 'rtl::OString' from 'const char [4]' on RHS of + (where LHS is of type 'rtl::OString') [loplugin:stringadd]}}
s = s + OString("xxx");
// no warning expected, no OStringLiteral1
s = s + OString(ch);
More information about the Libreoffice-commits
mailing list