summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNoel Grandin <noel.grandin@collabora.co.uk>2023-04-11 10:08:29 +0200
committerNoel Grandin <noel.grandin@collabora.co.uk>2023-04-11 14:19:13 +0200
commitde7ec4141d07d11330ffae8caafaa259fc8016b4 (patch)
tree6e99facb9207b4d35907aec3546e68fe14337200
parentdc80c92a1e63fd88560fd77261b96f6c5be97273 (diff)
loplugin:unnecessarygetstr check for OUString::number facilities
These were fixed by mike kaganski, but add to the plugin to prevent future mistakes Change-Id: I09b4b094a74e02399e017ccf5631c0d68052344a Reviewed-on: https://gerrit.libreoffice.org/c/core/+/150215 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
-rw-r--r--compilerplugins/clang/test/unnecessarygetstr.cxx8
-rw-r--r--compilerplugins/clang/unnecessarygetstr.cxx6
2 files changed, 12 insertions, 2 deletions
diff --git a/compilerplugins/clang/test/unnecessarygetstr.cxx b/compilerplugins/clang/test/unnecessarygetstr.cxx
index 68175872a4ea..d04d2ca28402 100644
--- a/compilerplugins/clang/test/unnecessarygetstr.cxx
+++ b/compilerplugins/clang/test/unnecessarygetstr.cxx
@@ -30,6 +30,10 @@ void test1(Foo& foo)
f1(true, s.getStr());
// expected-error@+1 {{unnecessary call to 'getStr' when passing to OString arg [loplugin:unnecessarygetstr]}}
foo.f1(true, s.getStr());
+ // expected-error@+1 {{unnecessary call to 'getStr' when passing to OString arg [loplugin:unnecessarygetstr]}}
+ foo.f1(true, OString::boolean(true).getStr());
+ // expected-error@+1 {{unnecessary call to 'getStr' when passing to OString arg [loplugin:unnecessarygetstr]}}
+ foo.f1(true, OString::number(12).getStr());
// avoid false +
OString aVal = "xx";
@@ -51,5 +55,9 @@ void test2(Foo2& foo)
f2(true, s.getStr());
// expected-error@+1 {{unnecessary call to 'getStr' when passing to string_view arg [loplugin:unnecessarygetstr]}}
foo.f2(true, s.getStr());
+ // expected-error@+1 {{unnecessary call to 'getStr' when passing to string_view arg [loplugin:unnecessarygetstr]}}
+ foo.f2(true, OString::boolean(true).getStr());
+ // expected-error@+1 {{unnecessary call to 'getStr' when passing to string_view arg [loplugin:unnecessarygetstr]}}
+ foo.f2(true, OString::number(12).getStr());
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */
diff --git a/compilerplugins/clang/unnecessarygetstr.cxx b/compilerplugins/clang/unnecessarygetstr.cxx
index 7ef5de6932d1..c72c9ae7598d 100644
--- a/compilerplugins/clang/unnecessarygetstr.cxx
+++ b/compilerplugins/clang/unnecessarygetstr.cxx
@@ -64,7 +64,8 @@ public:
if (!(tc2.Class("OString").Namespace("rtl").GlobalNamespace()
|| tc2.Class("OUString").Namespace("rtl").GlobalNamespace()
|| tc2.Class("OStringBuffer").Namespace("rtl").GlobalNamespace()
- || tc2.Class("OUStringBuffer").Namespace("rtl").GlobalNamespace()))
+ || tc2.Class("OUStringBuffer").Namespace("rtl").GlobalNamespace()
+ || tc2.ClassOrStruct("StringNumber").Namespace("rtl").GlobalNamespace()))
continue;
if (!loplugin::DeclCheck(e->getMethodDecl()).Function("getStr"))
continue;
@@ -89,7 +90,8 @@ public:
if (!(tc2.Class("OString").Namespace("rtl").GlobalNamespace()
|| tc2.Class("OUString").Namespace("rtl").GlobalNamespace()
|| tc2.Class("OStringBuffer").Namespace("rtl").GlobalNamespace()
- || tc2.Class("OUStringBuffer").Namespace("rtl").GlobalNamespace()))
+ || tc2.Class("OUStringBuffer").Namespace("rtl").GlobalNamespace()
+ || tc2.ClassOrStruct("StringNumber").Namespace("rtl").GlobalNamespace()))
continue;
if (!loplugin::DeclCheck(e->getMethodDecl()).Function("getStr"))
continue;