Skip to content

Commit 0070a78

Browse files
Fix #12088 FP constStatement with delete in loop increment (#5576)
1 parent 17ea101 commit 0070a78

2 files changed

Lines changed: 11 additions & 2 deletions

File tree

lib/checkother.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1910,8 +1910,12 @@ static bool isConstStatement(const Token *tok, bool cpp)
19101910
return false;
19111911
if (Token::Match(tok, "<<|>>") && !astIsIntegral(tok, false))
19121912
return false;
1913-
if (tok->astTop() && Token::simpleMatch(tok->astTop()->astOperand1(), "delete"))
1914-
return false;
1913+
const Token* tok2 = tok;
1914+
while (tok2) {
1915+
if (Token::simpleMatch(tok2->astOperand1(), "delete"))
1916+
return false;
1917+
tok2 = tok2->astParent();
1918+
}
19151919
if (Token::Match(tok, "&&|%oror%"))
19161920
return isConstStatement(tok->astOperand1(), cpp) && isConstStatement(tok->astOperand2(), cpp);
19171921
if (Token::Match(tok, "!|~|%cop%") && (tok->astOperand1() || tok->astOperand2()))

test/testother.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5877,6 +5877,11 @@ class TestOther : public TestFixture {
58775877
" std::array<std::array<double,3>,3> array;\n"
58785878
"}\n");
58795879
ASSERT_EQUALS("", errout.str());
5880+
5881+
check("void f(const std::vector<int*>& v) {\n" // #12088
5882+
" for (auto it = v.begin(); it != v.end(); delete *it++);\n"
5883+
"}\n");
5884+
ASSERT_EQUALS("", errout.str());
58805885
}
58815886

58825887
void duplicateBranch() {

0 commit comments

Comments
 (0)