summaryrefslogtreecommitdiff
path: root/compilerplugins
diff options
context:
space:
mode:
authorStephan Bergmann <sbergman@redhat.com>2021-02-09 20:48:37 +0100
committerStephan Bergmann <sbergman@redhat.com>2021-02-10 10:33:25 +0100
commit4cae353cae28f6530544ad5864d4ce3075ac5bcc (patch)
tree6d5adffbaa05ac9d1cd320ac393040490d3c289f /compilerplugins
parent4b92707c19ef47cdb9474224e83e5153c54b661d (diff)
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 <sbergman@redhat.com>
Diffstat (limited to 'compilerplugins')
-rw-r--r--compilerplugins/clang/stringliteralvar.cxx7
-rw-r--r--compilerplugins/clang/test/stringliteralvar.cxx8
2 files changed, 13 insertions, 2 deletions
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: */