From bf34b812a75add89a912df36761ec9dd77a479b0 Mon Sep 17 00:00:00 2001 From: Noel Grandin Date: Mon, 8 Jun 2015 10:09:34 +0100 Subject: [PATCH] New VclPtr clang plugin to catch potential problems. Change-Id: I2571c4384e4c2dbe411e171325e10d57a0afe5a0 Reviewed-on: https://gerrit.libreoffice.org/16235 Reviewed-by: Michael Meeks Tested-by: Michael Meeks --- compilerplugins/clang/vclwidgets.cxx | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/compilerplugins/clang/vclwidgets.cxx b/compilerplugins/clang/vclwidgets.cxx index fd79241a7dcd..7487fbf3c36f 100644 --- a/compilerplugins/clang/vclwidgets.cxx +++ b/compilerplugins/clang/vclwidgets.cxx @@ -46,6 +46,7 @@ public: bool VisitCallExpr(const CallExpr *); bool VisitDeclRefExpr(const DeclRefExpr* pDeclRefExpr); + bool VisitCXXConstructExpr( const CXXConstructExpr* expr ); private: bool isDisposeCallingSuperclassDispose(const CXXMethodDecl* pMethodDecl); bool mbCheckingMemcpy = false; @@ -581,6 +582,24 @@ bool VCLWidgets::VisitDeclRefExpr(const DeclRefExpr* pDeclRefExpr) return true; } +bool VCLWidgets::VisitCXXConstructExpr( const CXXConstructExpr* constructExpr ) +{ + if (ignoreLocation(constructExpr)) { + return true; + } + if (constructExpr->getConstructionKind() != CXXConstructExpr::CK_Complete) { + return true; + } + const CXXConstructorDecl* pConstructorDecl = constructExpr->getConstructor(); + const CXXRecordDecl* recordDecl = pConstructorDecl->getParent(); + if (isDerivedFromWindow(recordDecl)) { + report( + DiagnosticsEngine::Warning, + "Calling constructor of a Window-derived type directly. All such creation should go via VclPtr<>::Create", + constructExpr->getExprLoc()); + } + return true; +} loplugin::Plugin::Registration< VCLWidgets > X("vclwidgets");