diff options
author | Noel Grandin <noel.grandin@collabora.co.uk> | 2023-04-21 10:12:53 +0200 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2023-04-21 21:46:09 +0200 |
commit | f712c531336b2c44636a35ad682913550640e0d3 (patch) | |
tree | 17f96584923f9de4945479eb67d65fa7b2a2331e /compilerplugins/clang/test | |
parent | 90cbe03a0bd65151c197d3d4aeaf48a696f13fad (diff) |
loplugin:unnecessarygetstr extend to checking std::string::c_str
Change-Id: I17398e2a6a31a2c98ba8e54b5c8045f22aee8759
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/150749
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.cxx | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/compilerplugins/clang/test/unnecessarygetstr.cxx b/compilerplugins/clang/test/unnecessarygetstr.cxx index d04d2ca28402..12905ec5d233 100644 --- a/compilerplugins/clang/test/unnecessarygetstr.cxx +++ b/compilerplugins/clang/test/unnecessarygetstr.cxx @@ -18,6 +18,8 @@ #include <rtl/ustring.hxx> #include <sal/log.hxx> +namespace test1 +{ void f1(bool, const OString& s); struct Foo { @@ -41,7 +43,10 @@ void test1(Foo& foo) = "xx" + OUString(aVal.getStr(), aVal.getLength(), RTL_TEXTENCODING_ASCII_US); (void)aCompText; } +} +namespace test2 +{ // call to param that takes string_view void f2(bool, std::string_view); struct Foo2 @@ -60,4 +65,24 @@ void test2(Foo2& foo) // expected-error@+1 {{unnecessary call to 'getStr' when passing to string_view arg [loplugin:unnecessarygetstr]}} foo.f2(true, OString::number(12).getStr()); } +} + +namespace test3 +{ +// call to param that takes string_view +void f2(bool, std::string_view); +struct Foo2 +{ + void f2(bool, std::string_view); +}; +void test3(Foo2& foo) +{ + std::string s; + // expected-error@+1 {{unnecessary call to 'c_str' when passing to string_view arg [loplugin:unnecessarygetstr]}} + f2(true, s.c_str()); + // expected-error@+1 {{unnecessary call to 'c_str' when passing to string_view arg [loplugin:unnecessarygetstr]}} + foo.f2(true, s.c_str()); +} +} + /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ |