compilerplugins/clang/test/unnecessarygetstr.cxx | 8 ++++++++ compilerplugins/clang/unnecessarygetstr.cxx | 6 ++++-- 2 files changed, 12 insertions(+), 2 deletions(-)
New commits: commit de7ec4141d07d11330ffae8caafaa259fc8016b4 Author: Noel Grandin <noel.gran...@collabora.co.uk> AuthorDate: Tue Apr 11 10:08:29 2023 +0200 Commit: Noel Grandin <noel.gran...@collabora.co.uk> CommitDate: Tue Apr 11 14:19:13 2023 +0200 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.gran...@collabora.co.uk> 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;