diff --git a/src/checkother.cpp b/src/checkother.cpp index 33430b139..769e2ccd6 100644 --- a/src/checkother.cpp +++ b/src/checkother.cpp @@ -763,12 +763,12 @@ void CheckOther::CheckIncompleteStatement() if (parlevel != 0) continue; - if ((tok->str() != "#") && Token::Match(tok->next(), "; %str%") && !Token::Match(tok->tokAt(3), ",")) + if (Token::Match(tok, "[;{}] %str%") && !Token::Match(tok->tokAt(2), "[,}]")) { ErrorMessage::constStatement(_errorLogger, _tokenizer, tok->next(), "string"); } - if (!Token::Match(tok, "#") && Token::Match(tok->next(), "; %num%") && !Token::Match(tok->tokAt(3), ",")) + if (Token::Match(tok, "[;{}] %num%") && !Token::Match(tok->tokAt(2), "[,}]")) { ErrorMessage::constStatement(_errorLogger, _tokenizer, tok->next(), "numeric"); } diff --git a/test/testincompletestatement.cpp b/test/testincompletestatement.cpp index 3027c9819..0b3a0d062 100644 --- a/test/testincompletestatement.cpp +++ b/test/testincompletestatement.cpp @@ -60,6 +60,7 @@ private: { TEST_CASE(test1); TEST_CASE(test2); + TEST_CASE(test3); } void test1() @@ -79,15 +80,23 @@ private: void test2() { - // Todo: remove the ';' before the string - check("void foo()\n" "{\n" - " ;\"abc\";\n" + " \"abc\";\n" "}\n"); ASSERT_EQUALS(std::string("[test.cpp:3]: (style) Redundant code: Found a statement that begins with string constant\n"), errout.str()); } + + void test3() + { + check("void foo()\n" + "{\n" + " const char *str[] = { \"abc\" };\n" + "}\n"); + + ASSERT_EQUALS(std::string(""), errout.str()); + } }; REGISTER_TEST(TestIncompleteStatement)