[Libreoffice-commits] core.git: compilerplugins/clang
Stephan Bergmann (via logerrit)
logerrit at kemper.freedesktop.org
Tue Aug 4 16:47:48 UTC 2020
compilerplugins/clang/makeshared.cxx | 13 +++++++++++++
1 file changed, 13 insertions(+)
New commits:
commit 4f294e6976287b936d59035c4fe74ce18d3f132c
Author: Stephan Bergmann <sbergman at redhat.com>
AuthorDate: Tue Aug 4 14:51:41 2020 +0200
Commit: Stephan Bergmann <sbergman at redhat.com>
CommitDate: Tue Aug 4 18:47:10 2020 +0200
Avoid some unhelpful loplugin:makeshared
...like
> canvas/source/directx/dx_impltools.cxx(137,31): error: rather use make_shared than constructing from 'Gdiplus::Graphics *' [loplugin:makeshared]
> GraphicsSharedPtr pRet(Gdiplus::Graphics::FromImage(rBitmap.get()));
> ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
on Windows, where those functions like FromImage are provided by Windows (so we
can't help it that they are returning pointers)
Change-Id: Iae5c4b20d64cc6b38ff66409519fbd25f6e509cd
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/100095
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann <sbergman at redhat.com>
diff --git a/compilerplugins/clang/makeshared.cxx b/compilerplugins/clang/makeshared.cxx
index 9f12b6c3bd6b..9b512371d635 100644
--- a/compilerplugins/clang/makeshared.cxx
+++ b/compilerplugins/clang/makeshared.cxx
@@ -132,6 +132,19 @@ bool MakeShared::VisitCXXConstructExpr(CXXConstructExpr const* constructExpr)
return true;
else if (isa<CXXNullPtrLiteralExpr>(arg0))
return true;
+ else if (auto const call = dyn_cast<CallExpr>(arg0))
+ {
+ if (auto const decl = call->getDirectCallee())
+ {
+ // Don't warn about cases where e.g. the Bitmap* result of calling Windows'
+ // Bitmap::FromBITMAPINFO is wrapped in a shared_ptr:
+ if (decl->getReturnType()->isPointerType()
+ && compiler.getSourceManager().isInSystemHeader(decl->getLocation()))
+ {
+ return true;
+ }
+ }
+ }
StringRef fn = getFilenameOfLocation(
compiler.getSourceManager().getSpellingLoc(compat::getBeginLoc(constructExpr)));
More information about the Libreoffice-commits
mailing list