You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 985cbbe
Browse filesBrowse the repository at this point in the historyBrowse files
if (stepTok->isIncDecOp() && stepTok->astOperand1() && stepTok->astOperand1()->varId() == varId)
4920
+
returntrue;
4921
+
if (stepTok->isAssignmentOp() && stepTok->astOperand1() && stepTok->astOperand1()->varId() == varId) // TODO: WILL THIS RETURN TRUE IF STEP IS SOMETHING LIKE: i=i
4922
+
returntrue;
4923
+
returnfalse;
4924
+
}
4925
+
4926
+
staticboolhasForLoopExit(const Scope& scope)
4927
+
{
4928
+
for (const Token* tok = scope.bodyStart; tok != scope.bodyEnd; tok = tok->next()) {
4929
+
const Scope* escapeScope = tok->scope();
4930
+
if (!escapeScope || !escapeScope->isExecutable()) {
4931
+
if (escapeScope)
4932
+
tok = escapeScope->bodyEnd;
4933
+
continue;
4934
+
}
4935
+
if (const Token* lambdaEnd = findLambdaEndToken(tok)) {
4936
+
tok = lambdaEnd;
4937
+
continue;
4938
+
}
4939
+
if (!tok->isName() || !tok->isKeyword())
4940
+
continue;
4941
+
if (Token::Match(tok, "goto|return|throw")) //TODO: WILL THIS RETURN TRUE IF GOTO STAYS WITHIN THE LOOP
4942
+
returntrue;
4943
+
if (tok->str() != "break")
4944
+
continue;
4945
+
// break only exits this loop if it is not nested in an inner loop/switch
4946
+
while (escapeScope && escapeScope != &scope) {
4947
+
if (escapeScope->isLoopScope() || escapeScope->type == ScopeType::eSwitch)
" for (auto it = theMap.begin(); it != theMap.end();) {\n"
14604
+
" (void)*it;\n"
14605
+
" }\n"
14606
+
"}\n");
14607
+
ASSERT_EQUALS("[test.cpp:2:3]: (warning) The loop variable 'it' is not updated in this for-loop, so the loop might never terminate. [missingForLoopIncrement]\n", errout_str());
14608
+
14609
+
// Index variable with empty step
14610
+
check("void use(int);\n"
14611
+
"void f(int n) {\n"
14612
+
" for (int i = 0; i < n;) {\n"
14613
+
" use(i);\n"
14614
+
" }\n"
14615
+
"}\n");
14616
+
ASSERT_EQUALS("[test.cpp:3:3]: (warning) The loop variable 'i' is not updated in this for-loop, so the loop might never terminate. [missingForLoopIncrement]\n", errout_str());
14617
+
14618
+
// Empty body
14619
+
check("void f(int n) {\n"
14620
+
" for (int i = 0; i < n;) {\n"
14621
+
" }\n"
14622
+
"}\n");
14623
+
ASSERT_EQUALS("[test.cpp:2:3]: (warning) The loop variable 'i' is not updated in this for-loop, so the loop might never terminate. [missingForLoopIncrement]\n", errout_str());
0 commit comments