incomplete statement: minor update
This commit is contained in:
parent
9707217c15
commit
05e330ed38
|
@ -763,12 +763,12 @@ void CheckOther::CheckIncompleteStatement()
|
||||||
if (parlevel != 0)
|
if (parlevel != 0)
|
||||||
continue;
|
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");
|
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");
|
ErrorMessage::constStatement(_errorLogger, _tokenizer, tok->next(), "numeric");
|
||||||
}
|
}
|
||||||
|
|
|
@ -60,6 +60,7 @@ private:
|
||||||
{
|
{
|
||||||
TEST_CASE(test1);
|
TEST_CASE(test1);
|
||||||
TEST_CASE(test2);
|
TEST_CASE(test2);
|
||||||
|
TEST_CASE(test3);
|
||||||
}
|
}
|
||||||
|
|
||||||
void test1()
|
void test1()
|
||||||
|
@ -79,15 +80,23 @@ private:
|
||||||
|
|
||||||
void test2()
|
void test2()
|
||||||
{
|
{
|
||||||
// Todo: remove the ';' before the string
|
|
||||||
|
|
||||||
check("void foo()\n"
|
check("void foo()\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
" ;\"abc\";\n"
|
" \"abc\";\n"
|
||||||
"}\n");
|
"}\n");
|
||||||
|
|
||||||
ASSERT_EQUALS(std::string("[test.cpp:3]: (style) Redundant code: Found a statement that begins with string constant\n"), errout.str());
|
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)
|
REGISTER_TEST(TestIncompleteStatement)
|
||||||
|
|
Loading…
Reference in New Issue