[Libreoffice-commits] core.git: compilerplugins/clang include/cppuhelper sfx2/source

Stephan Bergmann sbergman at redhat.com
Thu Jan 5 08:18:09 UTC 2017


 compilerplugins/clang/salbool.cxx  |  104 +++++++++++++++++++++++++------------
 include/cppuhelper/proptypehlp.hxx |    6 +-
 sfx2/source/control/unoctitm.cxx   |    4 -
 3 files changed, 76 insertions(+), 38 deletions(-)

New commits:
commit ad9cfbcf02b74b1d1ca9cc5d51e5f3777cb9eab9
Author: Stephan Bergmann <sbergman at redhat.com>
Date:   Thu Jan 5 09:17:23 2017 +0100

    Don't exclude a var from loplugin:salbool merely because of use in >>=
    
    Change-Id: I1b8a3dfa1dc6b351ab0903a74eae19dfa6d0888d

diff --git a/compilerplugins/clang/salbool.cxx b/compilerplugins/clang/salbool.cxx
index 2da5811..bdb56ea 100644
--- a/compilerplugins/clang/salbool.cxx
+++ b/compilerplugins/clang/salbool.cxx
@@ -70,37 +70,72 @@ OverrideKind getOverrideKind(FunctionDecl const * decl) {
     return OverrideKind::MAYBE;
 }
 
+enum class BoolOverloadKind { No, Yes, CheckNext };
+
+BoolOverloadKind isBoolOverloadOf(
+    FunctionDecl const * f, FunctionDecl const * decl, bool mustBeDeleted)
+{
+    if (!mustBeDeleted || f->isDeleted()) {
+        unsigned n = decl->getNumParams();
+        if (f->getNumParams() == n) {
+            bool hasSB = false;
+            for (unsigned i = 0; i != n; ++i) {
+                QualType t1 { decl->getParamDecl(i)->getType() };
+                bool isSB = isSalBool(t1);
+                bool isSBRef = !isSB && t1->isReferenceType()
+                    && isSalBool(t1.getNonReferenceType());
+                QualType t2 { f->getParamDecl(i)->getType() };
+                if (!(isSB
+                      ? t2->isBooleanType()
+                      : isSBRef
+                      ? (t2->isReferenceType()
+                         && t2.getNonReferenceType()->isBooleanType())
+                      : t2.getCanonicalType() == t1.getCanonicalType()))
+                {
+                    return BoolOverloadKind::CheckNext;
+                }
+                hasSB |= isSB || isSBRef;
+            }
+            return hasSB ? BoolOverloadKind::Yes : BoolOverloadKind::No;
+                // cheaply protect against the case where decl would have no
+                // sal_Bool parameters at all and would match itself
+        }
+    }
+    return BoolOverloadKind::CheckNext;
+}
+
 //TODO: current implementation is not at all general, just tests what we
 // encounter in practice:
 bool hasBoolOverload(FunctionDecl const * decl, bool mustBeDeleted) {
-    unsigned n = decl->getNumParams();
-    auto res = decl->getDeclContext()->lookup(decl->getDeclName());
+    auto ctx = decl->getDeclContext();
+    if (!ctx->isLookupContext()) {
+        return false;
+    }
+    auto res = ctx->lookup(decl->getDeclName());
     for (auto d = res.begin(); d != res.end(); ++d) {
-        FunctionDecl const * f = dyn_cast<FunctionDecl>(*d);
-        if (f != nullptr && (!mustBeDeleted || f->isDeleted())) {
-            if (f->getNumParams() == n) {
-                bool hasSB = false;
-                for (unsigned i = 0; i != n; ++i) {
-                    QualType t1 { decl->getParamDecl(i)->getType() };
-                    bool isSB = isSalBool(t1);
-                    bool isSBRef = !isSB && t1->isReferenceType()
-                        && isSalBool(t1.getNonReferenceType());
-                    QualType t2 { f->getParamDecl(i)->getType() };
-                    if (!(isSB
-                          ? t2->isBooleanType()
-                          : isSBRef
-                          ? (t2->isReferenceType()
-                             && t2.getNonReferenceType()->isBooleanType())
-                          : t2 == t1))
-                    {
-                        goto next;
+        if (auto f = dyn_cast<FunctionDecl>(*d)) {
+            switch (isBoolOverloadOf(f, decl, mustBeDeleted)) {
+            case BoolOverloadKind::No:
+                return false;
+            case BoolOverloadKind::Yes:
+                return true;
+            case BoolOverloadKind::CheckNext:
+                break;
+            }
+        } else if (auto ftd = dyn_cast<FunctionTemplateDecl>(*d)) {
+            for (auto f: ftd->specializations()) {
+                if (f->getTemplateSpecializationKind()
+                    == TSK_ExplicitSpecialization)
+                {
+                    switch (isBoolOverloadOf(f, decl, mustBeDeleted)) {
+                    case BoolOverloadKind::No:
+                        return false;
+                    case BoolOverloadKind::Yes:
+                        return true;
+                    case BoolOverloadKind::CheckNext:
+                        break;
                     }
-                    hasSB |= isSB || isSBRef;
                 }
-                return hasSB;
-                    // cheaply protect against the case where decl would have no
-                    // sal_Bool parameters at all and would match itself
-            next:;
             }
         }
     }
@@ -226,14 +261,17 @@ bool SalBool::VisitCallExpr(CallExpr * expr) {
     if (d != nullptr) {
         FunctionDecl const * fd = dyn_cast<FunctionDecl>(d);
         if (fd != nullptr) {
-            PointerType const * pt = fd->getType()->getAs<PointerType>();
-            QualType t2(pt == nullptr ? fd->getType() : pt->getPointeeType());
-            ft = t2->getAs<FunctionProtoType>();
-            assert(
-                ft != nullptr || !compiler.getLangOpts().CPlusPlus
-                || (fd->getBuiltinID() != Builtin::NotBuiltin
-                    && isa<FunctionNoProtoType>(t2)));
-                // __builtin_*s have no proto type?
+            if (!hasBoolOverload(fd, false)) {
+                PointerType const * pt = fd->getType()->getAs<PointerType>();
+                QualType t2(
+                    pt == nullptr ? fd->getType() : pt->getPointeeType());
+                ft = t2->getAs<FunctionProtoType>();
+                assert(
+                    ft != nullptr || !compiler.getLangOpts().CPlusPlus
+                    || (fd->getBuiltinID() != Builtin::NotBuiltin
+                        && isa<FunctionNoProtoType>(t2)));
+                    // __builtin_*s have no proto type?
+            }
         } else {
             VarDecl const * vd = dyn_cast<VarDecl>(d);
             if (vd != nullptr) {
diff --git a/include/cppuhelper/proptypehlp.hxx b/include/cppuhelper/proptypehlp.hxx
index 20b3013..bcaefca 100644
--- a/include/cppuhelper/proptypehlp.hxx
+++ b/include/cppuhelper/proptypehlp.hxx
@@ -36,7 +36,7 @@ inline void SAL_CALL convertPropertyValue( target &value , const  css::uno::Any
     }
 }
 
-inline void SAL_CALL convertPropertyValue( sal_Bool & b   , const css::uno::Any & a )
+void convertPropertyValue(bool & b, const css::uno::Any & a)
 {
     if( !(a >>= b) ) {
         switch( a.getValueType().getTypeClass() ) {
@@ -71,8 +71,8 @@ inline void SAL_CALL convertPropertyValue( sal_Bool & b   , const css::uno::Any
     }
 }
 
-void convertPropertyValue(bool & target, css::uno::Any const & source) {
-    sal_Bool b;
+void convertPropertyValue(sal_Bool & target, css::uno::Any const & source) {
+    bool b;
     convertPropertyValue(b, source);
     target = b;
 }
diff --git a/sfx2/source/control/unoctitm.cxx b/sfx2/source/control/unoctitm.cxx
index 3e744e5..15e7256 100644
--- a/sfx2/source/control/unoctitm.cxx
+++ b/sfx2/source/control/unoctitm.cxx
@@ -1096,7 +1096,7 @@ static void InterceptLOKStateChangeEvent(const SfxViewFrame* pViewFrame, const c
              aEvent.FeatureURL.Path == "NumberFormatPercent" ||
              aEvent.FeatureURL.Path == "NumberFormatDate")
     {
-        sal_Bool aBool;
+        bool aBool;
 
         if (aEvent.IsEnabled && (aEvent.State >>= aBool))
         {
@@ -1105,7 +1105,7 @@ static void InterceptLOKStateChangeEvent(const SfxViewFrame* pViewFrame, const c
     }
     else if (aEvent.FeatureURL.Path == "ToggleMergeCells")
     {
-        sal_Bool aBool;
+        bool aBool;
 
         if (aEvent.IsEnabled && (aEvent.State >>= aBool))
         {


More information about the Libreoffice-commits mailing list