summaryrefslogtreecommitdiff
path: root/compilerplugins/clang/test/stringview.cxx
diff options
context:
space:
mode:
authorStephan Bergmann <sbergman@redhat.com>2020-12-04 16:24:56 +0100
committerStephan Bergmann <sbergman@redhat.com>2020-12-04 17:54:48 +0100
commit6c905fb6430b6ec43630e826f9afd935734f4c91 (patch)
tree6fefee2c2004bab1afd12bbb6c951a6b427604cb /compilerplugins/clang/test/stringview.cxx
parentfcb7fe3a082c200f69f10c1d3951761a7e41d6e0 (diff)
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 <sbergman@redhat.com>
Diffstat (limited to 'compilerplugins/clang/test/stringview.cxx')
-rw-r--r--compilerplugins/clang/test/stringview.cxx43
1 files changed, 40 insertions, 3 deletions
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 <sal/config.h>
+
+#include <string_view>
+
#include <rtl/strbuf.hxx>
#include <rtl/string.hxx>
#include <rtl/ustrbuf.hxx>
#include <rtl/ustring.hxx>
+#include <sal/types.h>
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: */