summaryrefslogtreecommitdiff
path: root/compilerplugins/clang/test
diff options
context:
space:
mode:
authorNoel Grandin <noel.grandin@collabora.co.uk>2019-10-14 14:27:57 +0200
committerNoel Grandin <noel.grandin@collabora.co.uk>2019-10-15 14:33:57 +0200
commitf13c6ad5f020a196a0e3aa6f28bda3dc185d465b (patch)
treef9aaab122974d36c134fb1723ec3c1c8df51eeef /compilerplugins/clang/test
parent9270f74466d0eb841babaa24997f608631c70341 (diff)
new loplugin:bufferadd
look for OUStringBuffer append sequences that can be turned into creating an OUString with + operations Change-Id: Ica840dc096000307b4a105fb4d9ec7588a15ade6 Reviewed-on: https://gerrit.libreoffice.org/80809 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'compilerplugins/clang/test')
-rw-r--r--compilerplugins/clang/test/bufferadd.cxx75
1 files changed, 75 insertions, 0 deletions
diff --git a/compilerplugins/clang/test/bufferadd.cxx b/compilerplugins/clang/test/bufferadd.cxx
new file mode 100644
index 000000000000..18c6055111a4
--- /dev/null
+++ b/compilerplugins/clang/test/bufferadd.cxx
@@ -0,0 +1,75 @@
+/* -*- 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 <rtl/strbuf.hxx>
+#include <rtl/string.hxx>
+#include <rtl/ustrbuf.hxx>
+#include <rtl/ustring.hxx>
+
+// ---------------------------------------------------------------
+// replaceing OUStringBuffer.append sequences to OUString+
+namespace test1
+{
+void f1()
+{
+ // expected-error@+1 {{convert this append sequence into a *String + sequence [loplugin:bufferadd]}}
+ OUStringBuffer v;
+ v.append("xxx");
+ v.append("xxx");
+}
+void f2()
+{
+ // expected-error@+1 {{convert this append sequence into a *String + sequence [loplugin:bufferadd]}}
+ OUStringBuffer v;
+ v.append("xxx").append("aaaa");
+}
+}
+
+namespace test2
+{
+void f2()
+{
+ // no warning expected
+ OUStringBuffer v;
+ v.append("xxx");
+ if (true)
+ v.append("yyyy");
+}
+void appendTo(OUStringBuffer&);
+void f3()
+{
+ // no warning expected
+ OUStringBuffer v;
+ appendTo(v);
+ v.append("xxx");
+}
+void f4()
+{
+ // no warning expected
+ OUStringBuffer v;
+ v.append("xxx");
+ v.setLength(0);
+}
+void f5()
+{
+ // no warning expected
+ OUStringBuffer v;
+ v.append("xxx");
+ v[1] = 'x';
+}
+void f6()
+{
+ // no warning expected
+ OUStringBuffer noel1("xxx");
+ while (true)
+ noel1.append("ffff").append("aaa");
+}
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */