Kaydet (Commit) 7b45044f authored tarafından Stephan Bergmann's avatar Stephan Bergmann

Also handle OUString with non-RTL_TEXTENCODING_ASCII_US encoding

(just in case)

Change-Id: I7ba2967c1cef81a3f6604077d876c8b993f7f16a
Reviewed-on: https://gerrit.libreoffice.org/42609Tested-by: 's avatarJenkins <ci@libreoffice.org>
Reviewed-by: 's avatarStephan Bergmann <sbergman@redhat.com>
üst e590e4dd
......@@ -756,6 +756,8 @@ bool StringConstant::VisitCXXConstructExpr(CXXConstructExpr const * expr) {
ChangeKind kind;
PassThrough pass;
bool simplify;
bool encIsAscii;
std::string enc;
switch (expr->getConstructor()->getNumParams()) {
case 1:
if (!loplugin::TypeCheck(
......@@ -846,11 +848,12 @@ bool StringConstant::VisitCXXConstructExpr(CXXConstructExpr const * expr) {
return true;
}
if (!expr->getArg(2)->EvaluateAsInt(
res, compiler.getASTContext())
|| res != 11) // RTL_TEXTENCODING_ASCII_US
res, compiler.getASTContext()))
{
return true;
}
encIsAscii = res == 11; // RTL_TEXTENCODING_ASCII_US
enc = res.toString(10);
if (!expr->getArg(3)->EvaluateAsInt(
res, compiler.getASTContext())
|| res != 0x333) // OSTRING_TO_OUSTRING_CVTFLAGS
......@@ -1056,9 +1059,10 @@ bool StringConstant::VisitCXXConstructExpr(CXXConstructExpr const * expr) {
if (simplify) {
report(
DiagnosticsEngine::Warning,
"simplify construction of %0 with %1",
("simplify construction of %0 with %1%select{ (but beware, the"
" given textencoding %3 is not RTL_TEXTENCODING_ASCII_US)|}2"),
expr->getExprLoc())
<< classdecl << describeChangeKind(kind)
<< classdecl << describeChangeKind(kind) << encIsAscii << enc
<< expr->getSourceRange();
}
return true;
......
......@@ -60,6 +60,10 @@ 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}}
(void)aFoo2;
(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 {{simplify construction of 'OUString' with string constant argument (but beware, the given textencoding 12 is not RTL_TEXTENCODING_ASCII_US) [loplugin:stringconstant]}}
(void) OUString("x\xA0x", 3, RTL_TEXTENCODING_ISO_8859_1);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment