summaryrefslogtreecommitdiff
path: root/compilerplugins
diff options
context:
space:
mode:
authorNoel Grandin <noel.grandin@collabora.co.uk>2019-10-15 20:24:10 +0200
committerNoel Grandin <noel.grandin@collabora.co.uk>2019-10-16 07:57:45 +0200
commit3ee177a14d8b816ef5b62500aeb54524c289e045 (patch)
tree982b524a298c2b2f959f5c858c81be9b3420566a /compilerplugins
parent820f340f285932bbb8d6739177e9bb81c23c1a5d (diff)
loplugin:stringadd look through a couple more known-good methods
Change-Id: Ifbdb3e41eae665f7dcaf5301aaba2b6e4662cf48 Reviewed-on: https://gerrit.libreoffice.org/80855 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'compilerplugins')
-rw-r--r--compilerplugins/clang/stringadd.cxx15
-rw-r--r--compilerplugins/clang/test/stringadd.cxx10
2 files changed, 17 insertions, 8 deletions
diff --git a/compilerplugins/clang/stringadd.cxx b/compilerplugins/clang/stringadd.cxx
index 7ae30922d5c8..986b2f938c7d 100644
--- a/compilerplugins/clang/stringadd.cxx
+++ b/compilerplugins/clang/stringadd.cxx
@@ -46,10 +46,13 @@ public:
{
std::string fn(handler.getMainFileName());
loplugin::normalizeDotDotInFilePath(fn);
- if (fn == SRCDIR "/sal/qa/rtl/oustring/rtl_OUString2.cxx"
- || fn == SRCDIR "/sal/qa/rtl/strings/test_oustring_concat.cxx"
- || fn == SRCDIR "/sal/qa/rtl/strings/test_ostring_concat.cxx"
- || fn == SRCDIR "/sal/qa/OStringBuffer/rtl_OStringBuffer.cxx")
+ if (loplugin::hasPathnamePrefix(fn, SRCDIR "/sal/qa/rtl/oustring/"))
+ return false;
+ if (loplugin::hasPathnamePrefix(fn, SRCDIR "/sal/qa/rtl/oustringbuffer/"))
+ return false;
+ if (loplugin::hasPathnamePrefix(fn, SRCDIR "/sal/qa/rtl/strings/"))
+ return false;
+ if (loplugin::hasPathnamePrefix(fn, SRCDIR "/sal/qa/OStringBuffer/"))
return false;
// there is an ifdef here, but my check is not working, not sure why
if (fn == SRCDIR "/pyuno/source/module/pyuno_runtime.cxx")
@@ -183,7 +186,6 @@ bool StringAdd::VisitCXXOperatorCallExpr(CXXOperatorCallExpr const* operatorCall
{
if (ignoreLocation(operatorCall))
return true;
- // TODO PlusEqual seems to generate temporaries, does not do the StringConcat optimisation
if (operatorCall->getOperator() != OO_Plus)
return true;
auto tc = loplugin::TypeCheck(operatorCall->getType()->getUnqualifiedDesugaredType());
@@ -261,7 +263,8 @@ bool StringAdd::isSideEffectFree(Expr const* expr)
if (calleeMethodDecl && calleeMethodDecl->getIdentifier())
{
auto name = calleeMethodDecl->getName();
- if (name == "number" || name == "unacquired")
+ if (callExpr->getNumArgs() > 0
+ && (name == "number" || name == "unacquired" || "boolean"))
{
auto tc = loplugin::TypeCheck(calleeMethodDecl->getParent());
if (tc.Class("OUString") || tc.Class("OString"))
diff --git a/compilerplugins/clang/test/stringadd.cxx b/compilerplugins/clang/test/stringadd.cxx
index c4fe15b16d68..27cc57f1395e 100644
--- a/compilerplugins/clang/test/stringadd.cxx
+++ b/compilerplugins/clang/test/stringadd.cxx
@@ -19,7 +19,7 @@ namespace test1
{
static const char XXX1[] = "xxx";
static const char XXX2[] = "xxx";
-void f(OUString s1, int i, OString o)
+void f1(OUString s1, int i, OString o)
{
OUString s2 = s1;
// expected-error@+1 {{simplify by merging with the preceding assignment [loplugin:stringadd]}}
@@ -41,7 +41,7 @@ void f(OUString s1, int i, OString o)
// expected-error@+1 {{simplify by merging with the preceding assignment [loplugin:stringadd]}}
s2 += OStringToOUString(o, RTL_TEXTENCODING_UTF8);
}
-void g(OString s1, int i, OUString u)
+void f2(OString s1, int i, OUString u)
{
OString s2 = s1;
// expected-error@+1 {{simplify by merging with the preceding assignment [loplugin:stringadd]}}
@@ -59,6 +59,12 @@ void g(OString s1, int i, OUString u)
// expected-error@+1 {{simplify by merging with the preceding assignment [loplugin:stringadd]}}
s2 += OUStringToOString(u, RTL_TEXTENCODING_ASCII_US);
}
+void f3(OUString aStr, int nFirstContent)
+{
+ OUString aFirstStr = aStr.copy(0, nFirstContent);
+ // expected-error@+1 {{simplify by merging with the preceding assignment [loplugin:stringadd]}}
+ aFirstStr += "...";
+}
}
namespace test2