diff --git a/lib/checkassert.cpp b/lib/checkassert.cpp index 249337dd9..35ef6b462 100644 --- a/lib/checkassert.cpp +++ b/lib/checkassert.cpp @@ -49,6 +49,9 @@ void CheckAssert::assertWithSideEffects() const Token *endTok = tok->next()->link(); for (const Token* tmp = tok->next(); tmp != endTok; tmp = tmp->next()) { + if (Token::simpleMatch(tmp, "sizeof (")) + tmp = tmp->linkAt(1); + checkVariableAssignment(tmp, tok->scope()); if (tmp->tokType() != Token::eFunction) diff --git a/test/testassert.cpp b/test/testassert.cpp index eac1f2339..efe957997 100644 --- a/test/testassert.cpp +++ b/test/testassert.cpp @@ -51,6 +51,7 @@ private: TEST_CASE(functionCallInAssert); TEST_CASE(memberFunctionCallInAssert); TEST_CASE(safeFunctionCallInAssert); + TEST_CASE(crash); } @@ -236,6 +237,13 @@ private: "}\n"); ASSERT_EQUALS("", errout.str()); } + + void crash() { + check("void foo() {\n" + " assert(sizeof(struct { int a[x++]; })==sizeof(int));\n" + "}"); + ASSERT_EQUALS("", errout.str()); + } }; REGISTER_TEST(TestAssert)