Fixed #3251 (Redundant code: Found a statement that begins with numeric constant)

This commit is contained in:
Daniel Marjamäki 2011-11-05 20:28:52 +01:00
parent 9903c8c0d9
commit d4a8184339
2 changed files with 14 additions and 1 deletions

View File

@ -1868,7 +1868,11 @@ void CheckOther::checkIncompleteStatement()
else if (tok->str() == "{" && Token::Match(tok->tokAt(-2), "%type% %var%"))
tok = tok->link();
else if (Token::Match(tok, "[;{}] %str%") || Token::Match(tok, "[;{}] %num% !!.")) {
else if (Token::Match(tok, "[;{}] %str%") || Token::Match(tok, "[;{}] %num%")) {
// No warning if numeric constant is followed by a "." or ","
if (Token::Match(tok->next(), "%num% [,.]"))
continue;
// bailout if there is a "? :" in this statement
bool bailout = false;
for (const Token *tok2 = tok->tokAt(2); tok2; tok2 = tok2->next()) {

View File

@ -67,6 +67,7 @@ private:
TEST_CASE(structinit); // #2462 : ABC abc{1,2,3};
TEST_CASE(returnstruct);
TEST_CASE(cast); // #3009 : (struct Foo *)123.a = 1;
TEST_CASE(increment); // #3251 : FP for increment
}
void test1() {
@ -194,6 +195,14 @@ private:
"}");
ASSERT_EQUALS("", errout.str());
}
void increment() {
check("void f() {\n"
" int x = 1;\n"
" x++, x++;\n"
"}");
ASSERT_EQUALS("", errout.str());
}
};
REGISTER_TEST(TestIncompleteStatement)