incomplete statement: minor update

This commit is contained in:
Daniel Marjamäki 2009-02-05 18:57:53 +00:00
parent 9707217c15
commit 05e330ed38
2 changed files with 14 additions and 5 deletions

View File

@ -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");
}

View File

@ -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)