summaryrefslogtreecommitdiff
path: root/compilerplugins/clang/test/stringview.cxx
diff options
context:
space:
mode:
authorStephan Bergmann <sbergman@redhat.com>2022-02-17 19:06:17 +0100
committerStephan Bergmann <sbergman@redhat.com>2022-02-17 21:45:49 +0100
commitee373f34ae1509e8d9fffaf4b5140ee9c35e8d41 (patch)
tree4b6b22600308a75dcfb9683775c9f976fddcbd7d /compilerplugins/clang/test/stringview.cxx
parentd1a2b80b9dc146c7fe63d2657e5506f49d6e5c0d (diff)
Extend loplugin:stringview to O[U]StringBuffer::makeStringAndClear
...at least when called on an rvalue. (The lvalue case would often be trickier to act upon, if the cleared object is still used later on.) Change-Id: I006e618da004b2127e9ed7381911c2d7b00b1169 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/130110 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.cxx27
1 files changed, 27 insertions, 0 deletions
diff --git a/compilerplugins/clang/test/stringview.cxx b/compilerplugins/clang/test/stringview.cxx
index a679ec59ea45..7e637175e259 100644
--- a/compilerplugins/clang/test/stringview.cxx
+++ b/compilerplugins/clang/test/stringview.cxx
@@ -10,6 +10,7 @@
#include <sal/config.h>
#include <string_view>
+#include <utility>
#include <rtl/strbuf.hxx>
#include <rtl/string.hxx>
@@ -81,6 +82,32 @@ void f1(OStringBuffer s1)
// expected-error@+1 {{rather than call toString, pass with a view [loplugin:stringview]}}
ConstructWithView(s1.toString());
}
+void makeStringAndClear(OUStringBuffer s)
+{
+ call_view(s.makeStringAndClear());
+ ConstructWithView(s.makeStringAndClear());
+ call_view((&s)->makeStringAndClear());
+ ConstructWithView((&s)->makeStringAndClear());
+ // expected-error@+1 {{rather than call makeStringAndClear on an rvalue, pass with a view [loplugin:stringview]}}
+ call_view(std::move(s).makeStringAndClear());
+ // expected-error@+1 {{rather than call makeStringAndClear on an rvalue, pass with a view [loplugin:stringview]}}
+ ConstructWithView(std::move(s).makeStringAndClear());
+ // expected-error@+1 {{rather than call makeStringAndClear on an rvalue, pass with a view [loplugin:stringview]}}
+ call_view((s).copy(1).makeStringAndClear());
+ // expected-error@+1 {{rather than call makeStringAndClear on an rvalue, pass with a view [loplugin:stringview]}}
+ ConstructWithView(s.copy(1).makeStringAndClear());
+}
+void makeStringAndClear(OStringBuffer s)
+{
+ call_view(s.makeStringAndClear());
+ ConstructWithView(s.makeStringAndClear());
+ call_view((&s)->makeStringAndClear());
+ ConstructWithView((&s)->makeStringAndClear());
+ // expected-error@+1 {{rather than call makeStringAndClear on an rvalue, pass with a view [loplugin:stringview]}}
+ call_view(std::move(s).makeStringAndClear());
+ // expected-error@+1 {{rather than call makeStringAndClear on an rvalue, pass with a view [loplugin:stringview]}}
+ ConstructWithView(std::move(s).makeStringAndClear());
+}
}
namespace test2