summaryrefslogtreecommitdiff
path: root/compilerplugins/clang/test
diff options
context:
space:
mode:
authorStephan Bergmann <sbergman@redhat.com>2020-11-12 08:13:40 +0100
committerStephan Bergmann <sbergman@redhat.com>2020-11-12 16:53:30 +0100
commitf34ac579fac16fff37bf00fe85d43ad6b938eca7 (patch)
tree0747c4d86bbf40a5093fb7a3215dd52a8e8586b2 /compilerplugins/clang/test
parentc45753847dfc2b4645dc2f7500a18ec2c5d438df (diff)
New loplugin:stringviewparam
...to "Find functions that take rtl::O[U]String parameters that can be generalized to take std::[u16]string_view instead." (Which in turn can avoid costly O[U]String constructions, see e.g. loplugin:stringview and subView.) Some of those functions' call sites, passing plain char string literals, needed to be adapted when converting them. Change-Id: I644ab546d7a0ce9e470ab9b3196e3e60d1e812bc Reviewed-on: https://gerrit.libreoffice.org/c/core/+/105622 Tested-by: Jenkins Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
Diffstat (limited to 'compilerplugins/clang/test')
-rw-r--r--compilerplugins/clang/test/stringviewparam.cxx53
1 files changed, 53 insertions, 0 deletions
diff --git a/compilerplugins/clang/test/stringviewparam.cxx b/compilerplugins/clang/test/stringviewparam.cxx
new file mode 100644
index 000000000000..afa0454b0b43
--- /dev/null
+++ b/compilerplugins/clang/test/stringviewparam.cxx
@@ -0,0 +1,53 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+#include "sal/config.h"
+
+#include <string_view>
+
+#include "rtl/string.hxx"
+#include "rtl/ustring.hxx"
+#include "sal/types.h"
+
+void f1a(std::string_view);
+// expected-error@+1 {{replace function parameter of type 'const rtl::OString &' with 'std::string_view' [loplugin:stringviewparam]}}
+char f1b(OString const& s)
+{
+ f1a(s);
+ if (s.isEmpty())
+ {
+ f1a(std::string_view(s));
+ }
+ return s[0];
+}
+
+void f2a(std::u16string_view);
+// expected-error@+1 {{replace function parameter of type 'const rtl::OUString &' with 'std::u16string_view' [loplugin:stringviewparam]}}
+sal_Unicode f2b(OUString const& s)
+{
+ f2a(s);
+ if (s.isEmpty())
+ {
+ f2a(std::u16string_view(s));
+ }
+ return s[0];
+}
+
+void f3a(OUString const&) {}
+using F3 = void(OUString const&);
+F3* f3b() { return f3a; }
+
+SAL_DLLPUBLIC_EXPORT void f4(OUString const&) {}
+
+template <typename T> void f5(T const&);
+template <> void f5<OUString>(OUString const&) {}
+
+void f6([[maybe_unused]] OUString const&) {}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */