From 6c905fb6430b6ec43630e826f9afd935734f4c91 Mon Sep 17 00:00:00 2001 From: Stephan Bergmann Date: Fri, 4 Dec 2020 16:24:56 +0100 Subject: Improve loplugin:stringview detection of unnecessary O[U]String construction Change-Id: Ia45119e11377e916a1e1deb5648ed9033c417d77 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/107228 Tested-by: Jenkins Reviewed-by: Stephan Bergmann --- compilerplugins/clang/test/stringview.cxx | 43 ++++++++++++++++++++++++++++--- 1 file changed, 40 insertions(+), 3 deletions(-) (limited to 'compilerplugins/clang/test/stringview.cxx') diff --git a/compilerplugins/clang/test/stringview.cxx b/compilerplugins/clang/test/stringview.cxx index 3c15d9cc4437..651e49e7bc27 100644 --- a/compilerplugins/clang/test/stringview.cxx +++ b/compilerplugins/clang/test/stringview.cxx @@ -7,10 +7,15 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ +#include + +#include + #include #include #include #include +#include void call_view(std::u16string_view) {} void call_view(std::string_view) {} @@ -93,12 +98,44 @@ void f4(OUString s1, OUString s2) } } -void f5() +void f5(char const* s1, sal_Int32 n1, char16_t const* s2, sal_Int32 n2) { - // expected-error@+1 {{instead of an empty 'rtl::OString', pass an empty 'std::string_view' [loplugin:stringview]}} + // expected-error@+1 {{instead of an 'rtl::OString', pass a 'std::string_view' [loplugin:stringview]}} call_view(OString()); - // expected-error@+1 {{instead of an empty 'rtl::OUString', pass an empty 'std::u16string_view' [loplugin:stringview]}} + // expected-error@+1 {{instead of an 'rtl::OString', pass a 'std::string_view' [loplugin:stringview]}} + call_view(OString("foo")); + // expected-error@+1 {{instead of an 'rtl::OString', pass a 'std::string_view' [loplugin:stringview]}} + call_view(OString(*s1)); + // expected-error@+1 {{instead of an 'rtl::OString', pass a 'std::string_view' [loplugin:stringview]}} + call_view(OString(s1)); + // expected-error@+1 {{instead of an 'rtl::OString', pass a 'std::string_view' [loplugin:stringview]}} + call_view(OString(s1, n1)); + constexpr OStringLiteral l1("foo"); + // expected-error@+1 {{instead of an 'rtl::OString', pass a 'std::string_view' [loplugin:stringview]}} + call_view(OString(l1)); + // expected-error@+1 {{instead of an 'rtl::OString', pass a 'std::string_view' [loplugin:stringview]}} + call_view(OString(std::string_view("foo"))); + // expected-error@+1 {{instead of an 'rtl::OString', pass a 'std::string_view' [loplugin:stringview]}} + call_view(OString(OString::number(0))); + // expected-error@+1 {{instead of an 'rtl::OUString', pass a 'std::u16string_view' [loplugin:stringview]}} call_view(OUString()); + // expected-error@+1 {{instead of an 'rtl::OUString', pass a 'std::u16string_view' [loplugin:stringview]}} + call_view(OUString("foo")); + // expected-error@+1 {{instead of an 'rtl::OUString', pass a 'std::u16string_view' [loplugin:stringview]}} + call_view(OUString(u"foo")); + // expected-error@+1 {{instead of an 'rtl::OUString', pass a 'std::u16string_view' [loplugin:stringview]}} + call_view(OUString(*s2)); + // expected-error@+1 {{instead of an 'rtl::OUString', pass a 'std::u16string_view' [loplugin:stringview]}} + call_view(OUString(s2)); + // expected-error@+1 {{instead of an 'rtl::OUString', pass a 'std::u16string_view' [loplugin:stringview]}} + call_view(OUString(s2, n2)); + constexpr OUStringLiteral l2(u"foo"); + // expected-error@+1 {{instead of an 'rtl::OUString', pass a 'std::u16string_view' [loplugin:stringview]}} + call_view(OUString(l2)); + // expected-error@+1 {{instead of an 'rtl::OUString', pass a 'std::u16string_view' [loplugin:stringview]}} + call_view(OUString(std::u16string_view(u"foo"))); + // expected-error@+1 {{instead of an 'rtl::OUString', pass a 'std::u16string_view' [loplugin:stringview]}} + call_view(OUString(OUString::number(0))); } /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ -- cgit