Incomplete statements: removed false positive when setting array of structures or multi-dimensional arrays.

This commit is contained in:
Leandro Penz 2009-02-12 12:59:43 +00:00
parent de2ee0a29d
commit 62a49282eb
2 changed files with 43 additions and 2 deletions

View File

@ -762,9 +762,29 @@ void CheckOther::CheckIncompleteStatement()
if (parlevel != 0)
continue;
if (tok->previous() && Token::Match(tok->previous(), "="))
if (Token::Match(tok, "= {"))
{
/* We are inside an assignment, so it's not a statement. */
/* We are in an assignment, so it's not a statement.
* Skip until ";" */
while (!Token::Match(tok, ";"))
{
int level = 0;
do
{
if (tok->str() == "(" || tok->str() == "{")
++level;
else if (tok->str() == ")" || tok->str() == "}")
--level;
tok = tok->next();
if (tok == NULL)
return;
}
while (level > 0);
}
continue;
}

View File

@ -65,6 +65,8 @@ private:
TEST_CASE(test5);
TEST_CASE(test_numeric);
TEST_CASE(intarray);
TEST_CASE(structarraynull);
TEST_CASE(structarray);
}
void test1()
@ -151,6 +153,25 @@ private:
check("int arr[] = { 100/2, 1*100 };\n");
ASSERT_EQUALS(std::string(""), errout.str());
}
void structarraynull()
{
check("struct st arr[] = {\n"
" { 100/2, 1*100 }\n"
" { 90, 70 }\n"
"}\n");
ASSERT_EQUALS(std::string(""), errout.str());
}
void structarray()
{
check("struct st arr[] = {\n"
" { 100/2, 1*100 }\n"
" { 90, 70 }\n"
"};\n");
ASSERT_EQUALS(std::string(""), errout.str());
}
};
REGISTER_TEST(TestIncompleteStatement)