summaryrefslogtreecommitdiff
path: root/compilerplugins/clang/test
diff options
context:
space:
mode:
authorNoel Grandin <noel.grandin@collabora.co.uk>2023-04-24 11:37:48 +0200
committerNoel Grandin <noel.grandin@collabora.co.uk>2023-04-24 18:04:50 +0200
commit5c1561561a859c561fb2321420f1abb7f1cedde3 (patch)
tree7a96cf8b32bd4c088298df3c4067f0d81f549057 /compilerplugins/clang/test
parent5e6d8efbf3fb456ca370df04b21d2e340d9831ad (diff)
loplugin:unnecessarygetstr extend to more std::string checking
suggested by mike kaganski Change-Id: I5f5f254142767aca45a6101abdd84a0163ca6a34 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/150936 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'compilerplugins/clang/test')
-rw-r--r--compilerplugins/clang/test/unnecessarygetstr.cxx47
1 files changed, 36 insertions, 11 deletions
diff --git a/compilerplugins/clang/test/unnecessarygetstr.cxx b/compilerplugins/clang/test/unnecessarygetstr.cxx
index 68ed153649ad..bb5fcc20d2ef 100644
--- a/compilerplugins/clang/test/unnecessarygetstr.cxx
+++ b/compilerplugins/clang/test/unnecessarygetstr.cxx
@@ -28,13 +28,13 @@ struct Foo
void test1(Foo& foo)
{
OString s;
- // expected-error@+1 {{unnecessary call to 'getStr' when passing to OString arg [loplugin:unnecessarygetstr]}}
+ // expected-error@+1 {{unnecessary call to 'getStr' when passing to OString constructor [loplugin:unnecessarygetstr]}}
f1(true, s.getStr());
- // expected-error@+1 {{unnecessary call to 'getStr' when passing to OString arg [loplugin:unnecessarygetstr]}}
+ // expected-error@+1 {{unnecessary call to 'getStr' when passing to OString constructor [loplugin:unnecessarygetstr]}}
foo.f1(true, s.getStr());
- // expected-error@+1 {{unnecessary call to 'getStr' when passing to OString arg [loplugin:unnecessarygetstr]}}
+ // expected-error@+1 {{unnecessary call to 'getStr' when passing to OString constructor [loplugin:unnecessarygetstr]}}
foo.f1(true, OString::boolean(true).getStr());
- // expected-error@+1 {{unnecessary call to 'getStr' when passing to OString arg [loplugin:unnecessarygetstr]}}
+ // expected-error@+1 {{unnecessary call to 'getStr' when passing to OString constructor [loplugin:unnecessarygetstr]}}
foo.f1(true, OString::number(12).getStr());
// avoid false +
@@ -49,22 +49,36 @@ namespace test2
{
// call to param that takes string_view
void f2(bool, std::string_view);
+void f2(bool, std::u16string_view);
struct Foo2
{
void f2(bool, std::string_view);
+ void f2(bool, std::u16string_view);
};
-void test2(Foo2& foo)
+void testOString(Foo2& foo)
{
OString s;
- // expected-error@+1 {{unnecessary call to 'getStr' when passing to string_view arg [loplugin:unnecessarygetstr]}}
+ // expected-error@+1 {{unnecessary call to 'getStr' when passing to string_view constructor [loplugin:unnecessarygetstr]}}
f2(true, s.getStr());
- // expected-error@+1 {{unnecessary call to 'getStr' when passing to string_view arg [loplugin:unnecessarygetstr]}}
+ // expected-error@+1 {{unnecessary call to 'getStr' when passing to string_view constructor [loplugin:unnecessarygetstr]}}
foo.f2(true, s.getStr());
- // expected-error@+1 {{unnecessary call to 'getStr' when passing to string_view arg [loplugin:unnecessarygetstr]}}
+ // expected-error@+1 {{unnecessary call to 'getStr' when passing to string_view constructor [loplugin:unnecessarygetstr]}}
foo.f2(true, OString::boolean(true).getStr());
- // expected-error@+1 {{unnecessary call to 'getStr' when passing to string_view arg [loplugin:unnecessarygetstr]}}
+ // expected-error@+1 {{unnecessary call to 'getStr' when passing to string_view constructor [loplugin:unnecessarygetstr]}}
foo.f2(true, OString::number(12).getStr());
}
+void testOUString(Foo2& foo)
+{
+ OUString s;
+ // expected-error@+1 {{unnecessary call to 'getStr' when passing to string_view constructor [loplugin:unnecessarygetstr]}}
+ f2(true, s.getStr());
+ // expected-error@+1 {{unnecessary call to 'getStr' when passing to string_view constructor [loplugin:unnecessarygetstr]}}
+ foo.f2(true, s.getStr());
+ // expected-error@+1 {{unnecessary call to 'getStr' when passing to string_view constructor [loplugin:unnecessarygetstr]}}
+ foo.f2(true, OUString::boolean(true).getStr());
+ // expected-error@+1 {{unnecessary call to 'getStr' when passing to string_view constructor [loplugin:unnecessarygetstr]}}
+ foo.f2(true, OUString::number(12).getStr());
+}
}
namespace test3
@@ -78,9 +92,9 @@ struct Foo2
void test3(Foo2& foo)
{
std::string s;
- // expected-error@+1 {{unnecessary call to 'c_str' when passing to string_view arg [loplugin:unnecessarygetstr]}}
+ // expected-error@+1 {{unnecessary call to 'c_str' when passing to string_view constructor [loplugin:unnecessarygetstr]}}
f2(true, s.c_str());
- // expected-error@+1 {{unnecessary call to 'c_str' when passing to string_view arg [loplugin:unnecessarygetstr]}}
+ // expected-error@+1 {{unnecessary call to 'c_str' when passing to string_view constructor [loplugin:unnecessarygetstr]}}
foo.f2(true, s.c_str());
}
}
@@ -95,4 +109,15 @@ void test()
}
}
+namespace test5
+{
+void test(std::string v, OString o)
+{
+ // expected-error@+1 {{unnecessary call to 'c_str' when passing to string_view constructor [loplugin:unnecessarygetstr]}}
+ std::string_view s1(v.c_str());
+ // expected-error@+1 {{unnecessary call to 'getStr' when passing to string constructor [loplugin:unnecessarygetstr]}}
+ std::string s2(o.getStr());
+}
+}
+
/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */