Kaydet (Commit) 9fcc7a90 authored tarafından Stephan Bergmann's avatar Stephan Bergmann

Try even harder to get at template args in loplugin:implicitboolconversion

After f82dc45b "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/46474Tested-by: 's avatarJenkins <ci@libreoffice.org>
Reviewed-by: 's avatarStephan Bergmann <sbergman@redhat.com>
üst 49a58e6e
......@@ -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());
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment