[Libreoffice-commits] core.git: compilerplugins/clang
Stephan Bergmann (via logerrit)
logerrit at kemper.freedesktop.org
Tue Jan 26 07:42:45 UTC 2021
compilerplugins/clang/stringconstant.cxx | 9 +++++++++
compilerplugins/clang/test/stringconstant.cxx | 2 ++
2 files changed, 11 insertions(+)
New commits:
commit 2682feb036fdf566028a9cab83ba8369484e459b
Author: Stephan Bergmann <sbergman at redhat.com>
AuthorDate: Mon Jan 25 20:30:14 2021 +0100
Commit: Stephan Bergmann <sbergman at redhat.com>
CommitDate: Tue Jan 26 08:42:09 2021 +0100
Adapt loplugin:stringconstant to many functions taking string_view args now
So look through (implicit) O[U]String to string_view conversions for those
arguments.
Change-Id: I1101d3f681d227ad0a76a4477bf52a1a3898cfdc
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/109926
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann <sbergman at redhat.com>
diff --git a/compilerplugins/clang/stringconstant.cxx b/compilerplugins/clang/stringconstant.cxx
index 372dbceb92ba..0447ba96ad1c 100644
--- a/compilerplugins/clang/stringconstant.cxx
+++ b/compilerplugins/clang/stringconstant.cxx
@@ -1954,6 +1954,15 @@ void StringConstant::handleStringCtor(
bool explicitFunctionalCastNotation, StringKind stringKind)
{
auto e0 = argExpr->IgnoreParenImpCasts();
+ if (auto const e1 = dyn_cast<CXXMemberCallExpr>(e0)) {
+ if (auto const e2 = dyn_cast<CXXConversionDecl>(e1->getMethodDecl())) {
+ if (loplugin::TypeCheck(e2->getConversionType()).ClassOrStruct("basic_string_view")
+ .StdNamespace())
+ {
+ e0 = e1->getImplicitObjectArgument()->IgnoreParenImpCasts();
+ }
+ }
+ }
auto e1 = dyn_cast<CXXFunctionalCastExpr>(e0);
if (e1 == nullptr) {
if (explicitFunctionalCastNotation) {
diff --git a/compilerplugins/clang/test/stringconstant.cxx b/compilerplugins/clang/test/stringconstant.cxx
index 1e325633d856..02f83b531068 100644
--- a/compilerplugins/clang/test/stringconstant.cxx
+++ b/compilerplugins/clang/test/stringconstant.cxx
@@ -110,6 +110,8 @@ int main() {
(void) OUString("\xC2\x80", 2, RTL_TEXTENCODING_UTF8); // expected-error {{simplify construction of 'OUString' with UTF-8 content as OUString(u"\u0080") [loplugin:stringconstant]}}
+ OUString().reverseCompareTo(OUString()); // expected-error {{in call of 'rtl::OUString::reverseCompareTo', replace default-constructed 'OUString' with an empty string literal [loplugin:stringconstant]}}
+
OUStringBuffer ub;
ub.append(""); // expected-error {{call of 'rtl::OUStringBuffer::append' with suspicious empty string constant argument [loplugin:stringconstant]}}
ub.append("foo\0bar"); // expected-error {{call of 'rtl::OUStringBuffer::append' with string constant argument containing embedded NULLs [loplugin:stringconstant]}}
More information about the Libreoffice-commits
mailing list