From f79123a823f44a8b70f94e31714e6aade019feb9 Mon Sep 17 00:00:00 2001 From: Stephan Bergmann Date: Wed, 27 Sep 2017 07:52:11 +0200 Subject: [PATCH] loplugin:stringconstant: Also handle u8"..." strings (just in case) Change-Id: Id8ce7436bacba874d9bc04915e42622e3cfca67a --- compilerplugins/clang/stringconstant.cxx | 2 +- compilerplugins/clang/test/stringconstant.cxx | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/compilerplugins/clang/stringconstant.cxx b/compilerplugins/clang/stringconstant.cxx index a4e0b79438b2..31cccb9b2c4a 100644 --- a/compilerplugins/clang/stringconstant.cxx +++ b/compilerplugins/clang/stringconstant.cxx @@ -1163,7 +1163,7 @@ bool StringConstant::isStringConstant( } clang::StringLiteral const * lit = dyn_cast(expr); if (lit != nullptr) { - if (!lit->isAscii()) { + if (!(lit->isAscii() || lit->isUTF8())) { return false; } unsigned n = lit->getLength(); diff --git a/compilerplugins/clang/test/stringconstant.cxx b/compilerplugins/clang/test/stringconstant.cxx index 41112d836520..8a830f12c717 100644 --- a/compilerplugins/clang/test/stringconstant.cxx +++ b/compilerplugins/clang/test/stringconstant.cxx @@ -66,6 +66,8 @@ int main() { (void) OUString("x\xA0x", 3, RTL_TEXTENCODING_ISO_8859_1); (void) OUString("xxx", 2, RTL_TEXTENCODING_ASCII_US); // expected-error {{suspicious 'rtl::OUString' constructor with literal of length 3 and non-matching length argument 2 [loplugin:stringconstant]}} + + (void) OUString(u8"xxx", 3, RTL_TEXTENCODING_ASCII_US); // expected-error {{simplify construction of 'OUString' with string constant argument [loplugin:stringconstant]}} }