loplugin:unusedfields, fix var taking ref
Change-Id: I0ea1f0c7488c140fca9f64de326c6ac588ece925
This commit is contained in:
@@ -611,6 +611,19 @@ void UnusedFields::checkReadOnly(const FieldDecl* fieldDecl, const Expr* memberE
|
||||
{
|
||||
if (!parent)
|
||||
{
|
||||
// check if we have an expression like
|
||||
// int& r = m_field;
|
||||
auto parentsRange = compiler.getASTContext().getParents(*child);
|
||||
if (parentsRange.begin() != parentsRange.end())
|
||||
{
|
||||
auto varDecl = dyn_cast_or_null<VarDecl>(parentsRange.begin()->get<Decl>());
|
||||
// The isImplicit() call is to avoid triggering when we see the vardecl which is part of a for-range statement,
|
||||
// which is of type 'T&&' and also an l-value-ref ?
|
||||
if (varDecl && !varDecl->isImplicit() && loplugin::TypeCheck(varDecl->getType()).LvalueReference().NonConst())
|
||||
{
|
||||
bPotentiallyWrittenTo = true;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
if (isa<CXXReinterpretCastExpr>(parent))
|
||||
|
Reference in New Issue
Block a user