[Libreoffice-commits] core.git: compilerplugins/clang
Stephan Bergmann
sbergman at redhat.com
Fri Sep 22 06:20:25 UTC 2017
compilerplugins/clang/stringconstant.cxx | 12 ++++++++----
compilerplugins/clang/test/stringconstant.cxx | 4 ++++
2 files changed, 12 insertions(+), 4 deletions(-)
New commits:
commit 7b45044fd14661202c658923842dd629cf52961c
Author: Stephan Bergmann <sbergman at redhat.com>
Date: Thu Sep 21 22:11:29 2017 +0200
Also handle OUString with non-RTL_TEXTENCODING_ASCII_US encoding
(just in case)
Change-Id: I7ba2967c1cef81a3f6604077d876c8b993f7f16a
Reviewed-on: https://gerrit.libreoffice.org/42609
Tested-by: Jenkins <ci at libreoffice.org>
Reviewed-by: Stephan Bergmann <sbergman at redhat.com>
diff --git a/compilerplugins/clang/stringconstant.cxx b/compilerplugins/clang/stringconstant.cxx
index a5ea9506f153..2eab378e443f 100644
--- a/compilerplugins/clang/stringconstant.cxx
+++ b/compilerplugins/clang/stringconstant.cxx
@@ -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;
diff --git a/compilerplugins/clang/test/stringconstant.cxx b/compilerplugins/clang/test/stringconstant.cxx
index 1b1eca2794bb..1a1f0c37580c 100644
--- a/compilerplugins/clang/test/stringconstant.cxx
+++ b/compilerplugins/clang/test/stringconstant.cxx
@@ -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);
}
More information about the Libreoffice-commits
mailing list