summaryrefslogtreecommitdiff
path: root/compilerplugins
diff options
context:
space:
mode:
authorStephan Bergmann <sbergman@redhat.com>2021-01-25 20:30:14 +0100
committerStephan Bergmann <sbergman@redhat.com>2021-01-26 08:42:09 +0100
commit2682feb036fdf566028a9cab83ba8369484e459b (patch)
treec482af8c1dcea66c813a62186857163fa7b07e5b /compilerplugins
parentc83166ce7126b3c3c6aca8f6d2ab9cd9e16f5763 (diff)
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@redhat.com>
Diffstat (limited to 'compilerplugins')
-rw-r--r--compilerplugins/clang/stringconstant.cxx9
-rw-r--r--compilerplugins/clang/test/stringconstant.cxx2
2 files changed, 11 insertions, 0 deletions
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]}}