From 4cae353cae28f6530544ad5864d4ce3075ac5bcc Mon Sep 17 00:00:00 2001 From: Stephan Bergmann Date: Tue, 9 Feb 2021 20:48:37 +0100 Subject: Fix loplugin:stringliteralvar ...detection of OUString( const sal_Unicode * value, sal_Int32 length ) ctor. (On platforms where sal_Int32 is a typedef for int, an argument that already is of type int will not be wrapped in an ImplicitCastExpr to the sal_Int32 typedef.) Change-Id: Ifc5456a62d42c1acad76ea949549dc24bd67201a Reviewed-on: https://gerrit.libreoffice.org/c/core/+/110654 Tested-by: Jenkins Reviewed-by: Stephan Bergmann --- compilerplugins/clang/stringliteralvar.cxx | 7 +++++-- compilerplugins/clang/test/stringliteralvar.cxx | 8 ++++++++ 2 files changed, 13 insertions(+), 2 deletions(-) (limited to 'compilerplugins') diff --git a/compilerplugins/clang/stringliteralvar.cxx b/compilerplugins/clang/stringliteralvar.cxx index ed1aa9e717d6..bf06f47f5089 100644 --- a/compilerplugins/clang/stringliteralvar.cxx +++ b/compilerplugins/clang/stringliteralvar.cxx @@ -74,7 +74,8 @@ public: { return true; } - switch (expr->getConstructor()->getNumParams()) + auto const ctor = expr->getConstructor(); + switch (ctor->getNumParams()) { case 1: { @@ -126,7 +127,9 @@ public: .Namespace("libreoffice_internal") .Namespace("rtl") .GlobalNamespace()) - || (loplugin::TypeCheck(e2->getType()).Typedef("sal_Int32").GlobalNamespace() + || (loplugin::TypeCheck(ctor->getParamDecl(1)->getType()) + .Typedef("sal_Int32") + .GlobalNamespace() && e2->isIntegerConstantExpr(compiler.getASTContext())))) { return true; diff --git a/compilerplugins/clang/test/stringliteralvar.cxx b/compilerplugins/clang/test/stringliteralvar.cxx index de67de5c7679..535f0e36ee72 100644 --- a/compilerplugins/clang/test/stringliteralvar.cxx +++ b/compilerplugins/clang/test/stringliteralvar.cxx @@ -87,4 +87,12 @@ void f9() f(OUString(literal, SAL_N_ELEMENTS(literal))); } +void f10() +{ + // expected-error@+1 {{change type of variable 'literal' from constant character array ('const sal_Unicode [3]') to OUStringLiteral [loplugin:stringliteralvar]}} + static sal_Unicode const literal[] = { 'f', 'o', 'o' }; + // expected-note@+1 {{first passed into a 'rtl::OUString' constructor here [loplugin:stringliteralvar]}} + f(OUString(literal, 3)); +} + /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ -- cgit