From f712c531336b2c44636a35ad682913550640e0d3 Mon Sep 17 00:00:00 2001 From: Noel Grandin Date: Fri, 21 Apr 2023 10:12:53 +0200 Subject: 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 --- compilerplugins/clang/test/unnecessarygetstr.cxx | 25 ++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'compilerplugins/clang/test') 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 #include +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: */ -- cgit