From 0070a78101a403e22bd5b39e2cfcfba97d620e41 Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Fri, 20 Oct 2023 10:25:31 +0200 Subject: [PATCH] Fix #12088 FP constStatement with delete in loop increment (#5576) --- lib/checkother.cpp | 8 ++++++-- test/testother.cpp | 5 +++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/lib/checkother.cpp b/lib/checkother.cpp index 8dec514a9..a8120b59c 100644 --- a/lib/checkother.cpp +++ b/lib/checkother.cpp @@ -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())) diff --git a/test/testother.cpp b/test/testother.cpp index 0a2c804cc..2912b1d59 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -5877,6 +5877,11 @@ private: " std::array,3> array;\n" "}\n"); ASSERT_EQUALS("", errout.str()); + + check("void f(const std::vector& v) {\n" // #12088 + " for (auto it = v.begin(); it != v.end(); delete *it++);\n" + "}\n"); + ASSERT_EQUALS("", errout.str()); } void duplicateBranch() {