improve loplugin:stringconstant

to find more places we can elide the OUString() constructor at call
sites

Change-Id: Ie09f3c61f2c4b4959c97dc98ebcbaf7c51d5d713
Reviewed-on: https://gerrit.libreoffice.org/71514
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
This commit is contained in:
Noel Grandin
2019-04-29 11:18:21 +02:00
parent 22f2cf3ccc
commit dd8d5e5795
46 changed files with 210 additions and 190 deletions

View File

@@ -17,6 +17,7 @@
extern void foo(OUString const &);
struct Foo {
Foo(int, const OUString &) {}
Foo(OUString const &, int) {}
Foo(OUString const &) {}
void foo(OUString const &) const {}
@@ -28,6 +29,11 @@ struct Foo2 {
void foo(OString const &) const {}
};
struct NegativeFoo {
NegativeFoo(const OString&, const OString& ) {}
NegativeFoo(const OString&, const OUString& ) {}
};
int main() {
char const s1[] = "foo";
char const * const s2 = "foo";
@@ -67,9 +73,15 @@ int main() {
(void)aFoo;
Foo aFoo2(OUString("xxx")); // expected-error {{in call of 'Foo::Foo', replace 'OUString' constructed from a string literal directly with the string literal}}
aFoo2.foo(OUString("xxx")); // expected-error {{in call of 'Foo::foo', replace 'OUString' constructed from a string literal directly with the string literal}}
Foo aFoo3(1, OUString("xxx")); // expected-error {{in call of 'Foo::Foo', replace 'OUString' constructed from a string literal directly with the string literal}}
(void)aFoo3;
Foo2 aFoo3(OString("xxx")); // expected-error {{in call of 'Foo2::Foo2', replace 'OUString' constructed from a string literal directly with the string literal}}
aFoo3.foo(OString("xxx")); // expected-error {{in call of 'Foo2::foo', replace 'OUString' constructed from a string literal directly with the string literal}}
Foo2 aFoo4(OString("xxx")); // expected-error {{in call of 'Foo2::Foo2', replace 'OUString' constructed from a string literal directly with the string literal}}
aFoo4.foo(OString("xxx")); // expected-error {{in call of 'Foo2::foo', replace 'OUString' constructed from a string literal directly with the string literal}}
// no warning expected
NegativeFoo aNegativeFoo(OString("xxx"), OUString("1"));
(void)aNegativeFoo;
(void) OUString("xxx", 3, RTL_TEXTENCODING_ASCII_US); // expected-error {{simplify construction of 'OUString' with string constant argument [loplugin:stringconstant]}}
(void) OUString("xxx", 3, RTL_TEXTENCODING_ISO_8859_1); // expected-error {{suspicious 'rtl::OUString' constructor with text encoding 12 but plain ASCII content; use 'RTL_TEXTENCODING_ASCII_US' instead [loplugin:stringconstant]}}