Fix #12088 FP constStatement with delete in loop increment (#5576)

This commit is contained in:
chrchr-github 2023-10-20 10:25:31 +02:00 committed by GitHub
parent 17ea101e7b
commit 0070a78101
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 2 deletions

View File

@ -1910,8 +1910,12 @@ static bool isConstStatement(const Token *tok, bool cpp)
return false;
if (Token::Match(tok, "<<|>>") && !astIsIntegral(tok, false))
return false;
if (tok->astTop() && Token::simpleMatch(tok->astTop()->astOperand1(), "delete"))
return false;
const Token* tok2 = tok;
while (tok2) {
if (Token::simpleMatch(tok2->astOperand1(), "delete"))
return false;
tok2 = tok2->astParent();
}
if (Token::Match(tok, "&&|%oror%"))
return isConstStatement(tok->astOperand1(), cpp) && isConstStatement(tok->astOperand2(), cpp);
if (Token::Match(tok, "!|~|%cop%") && (tok->astOperand1() || tok->astOperand2()))

View File

@ -5877,6 +5877,11 @@ private:
" std::array<std::array<double,3>,3> array;\n"
"}\n");
ASSERT_EQUALS("", errout.str());
check("void f(const std::vector<int*>& v) {\n" // #12088
" for (auto it = v.begin(); it != v.end(); delete *it++);\n"
"}\n");
ASSERT_EQUALS("", errout.str());
}
void duplicateBranch() {