From 4c1bf9d7790ca037933c3c6825d48736572a1886 Mon Sep 17 00:00:00 2001 From: Stephan Bergmann Date: Tue, 28 Sep 2021 20:09:55 +0200 Subject: Make loplugin:bufferadd look through O[U]String::operator std::[u16]string_view Change-Id: I79a32f64541a90b0b824f7721e8815c1e7c873ee Reviewed-on: https://gerrit.libreoffice.org/c/core/+/122788 Tested-by: Jenkins Reviewed-by: Stephan Bergmann --- compilerplugins/clang/bufferadd.cxx | 9 +++++++++ compilerplugins/clang/test/bufferadd.cxx | 6 ++++++ 2 files changed, 15 insertions(+) (limited to 'compilerplugins') diff --git a/compilerplugins/clang/bufferadd.cxx b/compilerplugins/clang/bufferadd.cxx index bc8c7065b2a1..cf2b6a011b4a 100644 --- a/compilerplugins/clang/bufferadd.cxx +++ b/compilerplugins/clang/bufferadd.cxx @@ -347,6 +347,15 @@ bool BufferAdd::isSideEffectFree(Expr const* expr) if (isSideEffectFree(callExpr->getArg(0))) return true; } + // O[U]String::operator std::[u16]string_view: + if (auto const d = dyn_cast_or_null(callExpr->getCalleeDecl())) + { + auto tc = loplugin::TypeCheck(d->getParent()); + if (tc.Class("OString") || tc.Class("OUString")) + { + return true; + } + } } // sometimes we have a constructor call on the RHS diff --git a/compilerplugins/clang/test/bufferadd.cxx b/compilerplugins/clang/test/bufferadd.cxx index a9f28b13b55a..c8057a6f497b 100644 --- a/compilerplugins/clang/test/bufferadd.cxx +++ b/compilerplugins/clang/test/bufferadd.cxx @@ -52,6 +52,12 @@ void f5(OUStringBuffer& input) OUStringBuffer v(input); v.append("aaaa"); } +void f6(OString const& s) +{ + // expected-error@+1 {{convert this append sequence into a *String + sequence [loplugin:bufferadd]}} + OUStringBuffer b("foo"); + b.append(OStringToOUString(s, RTL_TEXTENCODING_ASCII_US)); +} struct Footer { OStringBuffer m_descriptorStart; -- cgit