From 62a49282eb875e552dab7e2b1d0c499995f3f9c9 Mon Sep 17 00:00:00 2001 From: Leandro Penz Date: Thu, 12 Feb 2009 12:59:43 +0000 Subject: [PATCH] Incomplete statements: removed false positive when setting array of structures or multi-dimensional arrays. --- src/checkother.cpp | 24 ++++++++++++++++++++++-- test/testincompletestatement.cpp | 21 +++++++++++++++++++++ 2 files changed, 43 insertions(+), 2 deletions(-) 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)