diff options
author | Stephan Bergmann <sbergman@redhat.com> | 2017-01-05 09:17:23 +0100 |
---|---|---|
committer | Stephan Bergmann <sbergman@redhat.com> | 2017-01-05 09:17:47 +0100 |
commit | ad9cfbcf02b74b1d1ca9cc5d51e5f3777cb9eab9 (patch) | |
tree | dfe2a07e67bc5b1c48d8bd81ff092919f37270e3 | |
parent | This lock seems useless (diff) | |
download | core-ad9cfbcf02b74b1d1ca9cc5d51e5f3777cb9eab9.tar.gz core-ad9cfbcf02b74b1d1ca9cc5d51e5f3777cb9eab9.zip |
Don't exclude a var from loplugin:salbool merely because of use in >>=
Change-Id: I1b8a3dfa1dc6b351ab0903a74eae19dfa6d0888d
-rw-r--r-- | compilerplugins/clang/salbool.cxx | 104 | ||||
-rw-r--r-- | include/cppuhelper/proptypehlp.hxx | 6 | ||||
-rw-r--r-- | sfx2/source/control/unoctitm.cxx | 4 |
3 files changed, 76 insertions, 38 deletions
diff --git a/compilerplugins/clang/salbool.cxx b/compilerplugins/clang/salbool.cxx index 2da581111264..bdb56eae62be 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 20b301395f7a..bcaefca97470 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 3e744e5caae1..15e725693ccc 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)) { |