diff options
author | Noel Grandin <noel.grandin@collabora.co.uk> | 2019-10-13 08:47:47 +0200 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2019-10-14 08:26:14 +0200 |
commit | 9b5dad13b56bdde7c40970351af3da3a2c3c9350 (patch) | |
tree | abfd4b02743a0e6a93c51c026f4c53f0e21100bc /compilerplugins/clang/test/stringadd.cxx | |
parent | fa71320329999c968feb16ff65be328b5b8ff5e4 (diff) |
loplugin:stringadd look for unnecessary temporaries
which defeat the *StringConcat optimisation.
Also make StringConcat conversions treat a nullptr as an empty string,
to match the O*String(char*) constructors.
Change-Id: If45f5b4b6a535c97bfeeacd9ec472a7603a52e5b
Reviewed-on: https://gerrit.libreoffice.org/80724
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'compilerplugins/clang/test/stringadd.cxx')
-rw-r--r-- | compilerplugins/clang/test/stringadd.cxx | 44 |
1 files changed, 43 insertions, 1 deletions
diff --git a/compilerplugins/clang/test/stringadd.cxx b/compilerplugins/clang/test/stringadd.cxx index c9ef37f09bfd..0e0986258254 100644 --- a/compilerplugins/clang/test/stringadd.cxx +++ b/compilerplugins/clang/test/stringadd.cxx @@ -7,8 +7,13 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -#include <rtl/ustring.hxx> +#include <rtl/strbuf.hxx> #include <rtl/string.hxx> +#include <rtl/ustrbuf.hxx> +#include <rtl/ustring.hxx> + +// --------------------------------------------------------------- +// += tests namespace test1 { @@ -147,4 +152,41 @@ void g(int x, const Foo& aValidation) } } +// --------------------------------------------------------------- +// detecting OUString temporary construction in + + +namespace test9 +{ +OUString getByValue(); +const OUString& getByRef(); +void f1(OUString s, OUString t, int i, const char* pChar) +{ + // no warning expected + t = t + "xxx"; + // expected-error@+1 {{avoid constructing temporary copies during + [loplugin:stringadd]}} + s = s + OUString("xxx"); + // expected-error@+1 {{avoid constructing temporary copies during + [loplugin:stringadd]}} + s = s + OUString(getByRef()); + + // no warning expected + OUString a; + a = a + getByValue(); + + // no warning expected + OUString b; + b = b + (i == 1 ? "aaa" : "bbb"); + + // no warning expected + OUString c; + c = c + OUString(pChar, strlen(pChar), RTL_TEXTENCODING_UTF8); +} +void f2(char ch) +{ + OString s; + // expected-error@+1 {{avoid constructing temporary copies during + [loplugin:stringadd]}} + s = s + OString("xxx"); + // no warning expected, no OStringLiteral1 + s = s + OString(ch); +} +} /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ |