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

Stephan Bergmann sbergman at redhat.com
Fri Dec 15 12:25:54 UTC 2017


 compilerplugins/clang/implicitboolconversion.cxx |   39 +++++++++++++++--------
 1 file changed, 26 insertions(+), 13 deletions(-)

New commits:
commit 9fcc7a907bc10e9af76ff27db891f5b20ccc0d38
Author: Stephan Bergmann <sbergman at redhat.com>
Date:   Thu Dec 14 17:32:38 2017 +0100

    Try even harder to get at template args in loplugin:implicitboolconversion
    
    After f82dc45bdb9e930878447015291c5b90c9325b57 "Use the canonical TemplateDecl",
    builds on macOS (at least those using C++17 and recent trunk libc++) started to
    emit false warnings for that
    
        std::pair< Reference<XConnection>,sal_Bool> aRet;
        aRet.second = false;
    
    code in dbaccess/source/ui/dlg/DbAdminImpl.cxx.  There's a declaration of
    std::pair in type_traits and a definition in utility, and for some reason the
    declaration in type_traits was deemed the canonical one, while the
    SubstTemplateTypeParmType pointed at the definition in utility.  So just check
    both, the original and the canonical TemplateDecl.
    
    Change-Id: I2fb9d5172c031e6ad4989b215f19d11a4b17f743
    Reviewed-on: https://gerrit.libreoffice.org/46474
    Tested-by: Jenkins <ci at libreoffice.org>
    Reviewed-by: Stephan Bergmann <sbergman at redhat.com>

diff --git a/compilerplugins/clang/implicitboolconversion.cxx b/compilerplugins/clang/implicitboolconversion.cxx
index 5c658fd9c715..41f6fd56bcae 100644
--- a/compilerplugins/clang/implicitboolconversion.cxx
+++ b/compilerplugins/clang/implicitboolconversion.cxx
@@ -80,6 +80,25 @@ SubstTemplateTypeParmType const * getAsSubstTemplateTypeParmType(QualType type)
     }
 }
 
+QualType reconstructTemplateArgumentType(
+    TemplateDecl const * decl, TemplateSpecializationType const * specializationType,
+    SubstTemplateTypeParmType const * parmType)
+{
+    TemplateParameterList const * ps = decl->getTemplateParameters();
+    auto i = std::find(ps->begin(), ps->end(), parmType->getReplacedParameter()->getDecl());
+    if (i == ps->end()) {
+        return {};
+    }
+    if (ps->size() != specializationType->getNumArgs()) { //TODO
+        return {};
+    }
+    TemplateArgument const & arg = specializationType->getArg(i - ps->begin());
+    if (arg.getKind() != TemplateArgument::Type) {
+        return {};
+    }
+    return arg.getAsType();
+}
+
 bool areSameTypedef(QualType type1, QualType type2) {
     // type1.getTypePtr() == typ2.getTypePtr() fails for e.g. ::sal_Bool vs.
     // sal_Bool:
@@ -159,28 +178,22 @@ bool isBoolExpr(Expr const * expr) {
                 if (td == nullptr) {
                     break;
                 }
-                td = cast<TemplateDecl>(td->getCanonicalDecl());
-                TemplateParameterList const * ps = td->getTemplateParameters();
                 SubstTemplateTypeParmType const * t2
                     = getAsSubstTemplateTypeParmType(
                         me->getMemberDecl()->getType());
                 if (t2 == nullptr) {
                     break;
                 }
-                auto i = std::find(
-                    ps->begin(), ps->end(),
-                    t2->getReplacedParameter()->getDecl());
-                if (i == ps->end()) {
-                    break;
-                }
-                if (ps->size() != t->getNumArgs()) { //TODO
-                    break;
+                ty = reconstructTemplateArgumentType(td, t, t2);
+                if (ty.isNull()) {
+                    auto const canon = cast<TemplateDecl>(td->getCanonicalDecl());
+                    if (canon != td) {
+                        ty = reconstructTemplateArgumentType(canon, t, t2);
+                    }
                 }
-                TemplateArgument const & arg = t->getArg(i - ps->begin());
-                if (arg.getKind() != TemplateArgument::Type) {
+                if (ty.isNull()) {
                     break;
                 }
-                ty = arg.getAsType();
             } else {
                 CXXOperatorCallExpr const * op
                     = dyn_cast<CXXOperatorCallExpr>(stack.top());


More information about the Libreoffice-commits mailing list