Fixed #3251 (Redundant code: Found a statement that begins with numeric constant)
This commit is contained in:
parent
9903c8c0d9
commit
d4a8184339
|
@ -1868,7 +1868,11 @@ void CheckOther::checkIncompleteStatement()
|
||||||
else if (tok->str() == "{" && Token::Match(tok->tokAt(-2), "%type% %var%"))
|
else if (tok->str() == "{" && Token::Match(tok->tokAt(-2), "%type% %var%"))
|
||||||
tok = tok->link();
|
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
|
// bailout if there is a "? :" in this statement
|
||||||
bool bailout = false;
|
bool bailout = false;
|
||||||
for (const Token *tok2 = tok->tokAt(2); tok2; tok2 = tok2->next()) {
|
for (const Token *tok2 = tok->tokAt(2); tok2; tok2 = tok2->next()) {
|
||||||
|
|
|
@ -67,6 +67,7 @@ private:
|
||||||
TEST_CASE(structinit); // #2462 : ABC abc{1,2,3};
|
TEST_CASE(structinit); // #2462 : ABC abc{1,2,3};
|
||||||
TEST_CASE(returnstruct);
|
TEST_CASE(returnstruct);
|
||||||
TEST_CASE(cast); // #3009 : (struct Foo *)123.a = 1;
|
TEST_CASE(cast); // #3009 : (struct Foo *)123.a = 1;
|
||||||
|
TEST_CASE(increment); // #3251 : FP for increment
|
||||||
}
|
}
|
||||||
|
|
||||||
void test1() {
|
void test1() {
|
||||||
|
@ -194,6 +195,14 @@ private:
|
||||||
"}");
|
"}");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void increment() {
|
||||||
|
check("void f() {\n"
|
||||||
|
" int x = 1;\n"
|
||||||
|
" x++, x++;\n"
|
||||||
|
"}");
|
||||||
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
REGISTER_TEST(TestIncompleteStatement)
|
REGISTER_TEST(TestIncompleteStatement)
|
||||||
|
|
Loading…
Reference in New Issue