[Libreoffice-commits] core.git: compilerplugins/clang

Libreoffice Gerrit user logerrit at kemper.freedesktop.org
Thu Sep 13 11:32:23 UTC 2018


 compilerplugins/clang/simplifyconstruct.cxx      |    2 +-
 compilerplugins/clang/test/simplifyconstruct.cxx |   21 +++++++++++++++++++--
 2 files changed, 20 insertions(+), 3 deletions(-)

New commits:
commit b74db4138342f646fda061eac5d6759ecf2c366f
Author:     Noel Grandin <noel.grandin at collabora.co.uk>
AuthorDate: Thu Sep 13 13:31:41 2018 +0200
Commit:     Noel Grandin <noel.grandin at collabora.co.uk>
CommitDate: Thu Sep 13 13:31:41 2018 +0200

    loplugin:simplifyconstruct exclude std::unique_ptr with custom deleter
    
    Change-Id: I8f4ba883747a2aace88786ef807fd7c338bef5da

diff --git a/compilerplugins/clang/simplifyconstruct.cxx b/compilerplugins/clang/simplifyconstruct.cxx
index 2a80cdefe4b2..fd5ba5027d01 100644
--- a/compilerplugins/clang/simplifyconstruct.cxx
+++ b/compilerplugins/clang/simplifyconstruct.cxx
@@ -51,7 +51,7 @@ bool SimplifyConstruct::VisitCXXConstructExpr(CXXConstructExpr const* constructE
                 .Namespace("com")
                 .GlobalNamespace())
         return true;
-    if (constructExpr->getNumArgs() > 0
+    if (constructExpr->getNumArgs() == 1
         && isa<CXXNullPtrLiteralExpr>(constructExpr->getArg(0)->IgnoreParenImpCasts()))
     {
         report(DiagnosticsEngine::Warning,
diff --git a/compilerplugins/clang/test/simplifyconstruct.cxx b/compilerplugins/clang/test/simplifyconstruct.cxx
index ce8a70aab272..3ff6ddf22c64 100644
--- a/compilerplugins/clang/test/simplifyconstruct.cxx
+++ b/compilerplugins/clang/test/simplifyconstruct.cxx
@@ -15,11 +15,11 @@ struct Foo
     void acquire();
     void release();
 };
-class Foo16
+class Foo1
 {
     std::unique_ptr<int> m_pbar1;
     rtl::Reference<Foo> m_pbar2;
-    Foo16()
+    Foo1()
         : m_pbar1(nullptr)
         // expected-error at -1 {{no need to explicitly init this with nullptr, just use default constructor [loplugin:simplifyconstruct]}}
         , m_pbar2(nullptr)
@@ -27,4 +27,21 @@ class Foo16
     {
     }
 };
+
+// no warning expected when using std::unique_ptr constructor with a custom deleter
+struct ITypeLib
+{
+};
+struct IUnknown
+{
+    void Release();
+};
+void func2()
+{
+    std::unique_ptr<IUnknown, void (*)(IUnknown * p)> aITypeLibGuard(nullptr, [](IUnknown* p) {
+        if (p)
+            p->Release();
+    });
+}
+
 /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */


More information about the Libreoffice-commits mailing list