diff --git a/src/checkother.cpp b/src/checkother.cpp index 1d229509c..12eed6cb4 100644 --- a/src/checkother.cpp +++ b/src/checkother.cpp @@ -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; } diff --git a/test/testincompletestatement.cpp b/test/testincompletestatement.cpp index 6f9b3e1ac..101560e99 100644 --- a/test/testincompletestatement.cpp +++ b/test/testincompletestatement.cpp @@ -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)