summaryrefslogtreecommitdiff
path: root/compilerplugins/clang
diff options
context:
space:
mode:
Diffstat (limited to 'compilerplugins/clang')
-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]}}