diff options
author | Stephan Bergmann <sbergman@redhat.com> | 2021-01-27 16:45:22 +0100 |
---|---|---|
committer | Stephan Bergmann <sbergman@redhat.com> | 2021-01-27 23:24:42 +0100 |
commit | aa2064c5c5f23f6f4b7bc44e12345b37f66995bc (patch) | |
tree | a5073b6d0b0c5846575671975341f0e0b393d98d /compilerplugins | |
parent | 686582b4890f458b6b8ee0e1ab19d9ad64793c85 (diff) |
Improve loplugin:stringliteralvar
...to also consider O[U]String ctors taking pointer and length
Change-Id: Iea5041634bfbf5054a1317701e30b56f72e940fb
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/110025
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
Diffstat (limited to 'compilerplugins')
-rw-r--r-- | compilerplugins/clang/stringliteralvar.cxx | 14 | ||||
-rw-r--r-- | compilerplugins/clang/test/stringliteralvar.cxx | 9 |
2 files changed, 17 insertions, 6 deletions
diff --git a/compilerplugins/clang/stringliteralvar.cxx b/compilerplugins/clang/stringliteralvar.cxx index 348193421a61..ed1aa9e717d6 100644 --- a/compilerplugins/clang/stringliteralvar.cxx +++ b/compilerplugins/clang/stringliteralvar.cxx @@ -120,12 +120,14 @@ public: return true; } auto const e2 = expr->getArg(1); - if (!(isa<CXXDefaultArgExpr>(e2) - && loplugin::TypeCheck(e2->getType()) - .Struct("Dummy") - .Namespace("libreoffice_internal") - .Namespace("rtl") - .GlobalNamespace())) + if (!((isa<CXXDefaultArgExpr>(e2) + && loplugin::TypeCheck(e2->getType()) + .Struct("Dummy") + .Namespace("libreoffice_internal") + .Namespace("rtl") + .GlobalNamespace()) + || (loplugin::TypeCheck(e2->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 25a85f90a5a3..de67de5c7679 100644 --- a/compilerplugins/clang/test/stringliteralvar.cxx +++ b/compilerplugins/clang/test/stringliteralvar.cxx @@ -12,6 +12,7 @@ #include <vector> #include <rtl/ustring.hxx> +#include <sal/macros.h> // expected-error@+1 {{change type of variable 'literal1' from constant character array ('const char [4]') to OStringLiteral [loplugin:stringliteralvar]}} char const literal1[] = "foo"; @@ -78,4 +79,12 @@ void f8() (void)sizeof literal; } +void f9() +{ + // 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, SAL_N_ELEMENTS(literal))); +} + /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ |