Detect different vars in condition and increment

This commit is contained in:
Matheus Aguiar 2023-09-19 16:53:48 -03:00
parent 0acab9d07e
commit 2528ff31ee

View File

@ -481,6 +481,12 @@ struct SimpleCounterForLoopChecker: public PostTypeChecker::Checker
if (!lhsIdentifier || !lhsIntegerType || !commonIntegerType || *lhsIntegerType != *commonIntegerType)
return false;
if (
auto const* incExpressionIdentifier = dynamic_cast<Identifier const*>(&simplePostExpression->subExpression());
incExpressionIdentifier->annotation().referencedDeclaration != lhsIdentifier->annotation().referencedDeclaration
)
return false;
LValueChecker lhsLValueChecker{*lhsIdentifier};
_forStatement.body().accept(lhsLValueChecker);
return !lhsLValueChecker.willBeWrittenTo();