diff --git a/lib/astutils.cpp b/lib/astutils.cpp index b2fc47fe4c7..d6dfd4afadb 100644 --- a/lib/astutils.cpp +++ b/lib/astutils.cpp @@ -825,6 +825,8 @@ static T* getCondTokImpl(T* tok) return tok->next()->astOperand2()->astOperand2()->astOperand1(); if (Token::simpleMatch(tok->next()->astOperand2(), ";")) return tok->next()->astOperand2()->astOperand1(); + if (tok->isName() && !tok->isControlFlowKeyword()) + return nullptr; return tok->next()->astOperand2(); } diff --git a/test/testvalueflow.cpp b/test/testvalueflow.cpp index b39822365e3..fb14f75ed54 100644 --- a/test/testvalueflow.cpp +++ b/test/testvalueflow.cpp @@ -7467,6 +7467,16 @@ class TestValueFlow : public TestFixture { code = "void f() { int& a = *&a; }\n"; // #12511 valueOfTok(code, "="); + + code = "void g(int*);\n" // #12716 + "void f(int a) {\n" + " do {\n" + " if (a)\n" + " break;\n" + " g((int[256]) { 0 });\n" + " } while (true);\n" + "}\n"; + valueOfTok(code, "0"); } void valueFlowHang() {