// unusual case where a user constructor sets a field to one value, and a copy constructor sets it to a different value if (fn == SRCDIR "/sw/source/core/attr/hints.cxx") return; if (fn == SRCDIR "/oox/source/core/contexthandler2.cxx") return;
bool StaticConstField::TraverseConstructorInitializer(CXXCtorInitializer* init)
{ if (!init->getSourceLocation().isValid() || ignoreLocation(init->getSourceLocation())) returntrue; if (!init->getMember()) returntrue; if (!init->getInit()) returntrue; if (!m_currentConstructor || m_currentConstructor->isCopyOrMoveConstructor()) returntrue; if (!m_currentConstructor->getParent()->isCompleteDefinition()) returntrue; if (m_excluded.find(init->getMember()) != m_excluded.end()) returntrue; auto type = init->getMember()->getType(); auto tc = loplugin::TypeCheck(type); if (!tc.Const()) returntrue;
bool found = false;
std::string value; autoconst initexpr = init->getInit()->IgnoreImplicit(); if (tc.Const().Class("OUString").Namespace("rtl").GlobalNamespace()
|| tc.Const().Class("OString").Namespace("rtl").GlobalNamespace())
{ if (auto constructExpr = dyn_cast<CXXConstructExpr>(initexpr))
{ if (constructExpr->getNumArgs() >= 1
&& isa<clang::StringLiteral>(constructExpr->getArg(0)))
{
value = dyn_cast<clang::StringLiteral>(constructExpr->getArg(0))->getString().str();
found = true;
}
}
} elseif (type->isFloatingType())
{
APFloat x1(0.0f); if (initexpr->EvaluateAsFloat(x1, compiler.getASTContext()))
{
std::string s;
llvm::raw_string_ostream os(s);
x1.print(os);
value = os.str();
found = true;
}
} // ignore this, it seems to trigger an infinite recursion elseif (isa<UnaryExprOrTypeTraitExpr>(initexpr))
; // ignore this, calling EvaluateAsInt on it will crash clang elseif (initexpr->isValueDependent())
; else
{
APSInt x1; if (compat::EvaluateAsInt(initexpr, x1, compiler.getASTContext()))
{
value = compat::toString(x1, 10);
found = true;
}
}
if (!found)
{
m_potentials.erase(init->getMember());
m_excluded.insert(init->getMember()); returntrue;
}
auto findIt = m_potentials.find(init->getMember()); if (findIt != m_potentials.end())
{ if (findIt->second.value != value)
{
m_potentials.erase(findIt);
m_excluded.insert(init->getMember());
} else
findIt->second.inits.push_back(init);
} else
{
Data& data = m_potentials[init->getMember()];
data.inits.push_back(init);
data.value = value;
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.