Fixed #9816 (False positive: Condition '!b' is always false in nested do-while loop)

This commit is contained in:
Paul 2020-07-24 08:12:36 +02:00 committed by Daniel Marjamäki
parent aa066755be
commit 46e008c3e2
2 changed files with 18 additions and 0 deletions

View File

@ -313,6 +313,10 @@ struct ForwardTraversal {
return Progress::Break;
} else if (scope->type == Scope::eLambda) {
return Progress::Break;
} else if (scope->type == Scope::eDo && Token::simpleMatch(tok, "} while (")) {
if (updateLoop(tok, tok->tokAt(2)->astOperand2()) == Progress::Break)
return Progress::Break;
tok = tok->linkAt(2);
} else if (Token::simpleMatch(tok->next(), "else {")) {
tok = tok->linkAt(2);
}

View File

@ -3409,6 +3409,20 @@ private:
"}\n");
ASSERT_EQUALS("", errout.str());
// #9816
check("bool g();\n"
"void f() {\n"
" bool b = false;\n"
" do {\n"
" do {\n"
" if (g())\n"
" break;\n"
" b = true;\n"
" } while(false);\n"
" } while(!b);\n"
"}\n");
ASSERT_EQUALS("", errout.str());
}
void alwaysTrueInfer() {