Don't warn about redundant number statement in '({ do_something(); 0; })'
This commit is contained in:
parent
9865105f68
commit
272fcc18d8
|
@ -2178,7 +2178,7 @@ void CheckOther::checkIncompleteStatement()
|
|||
else if (Token::simpleMatch(tok,"> {") && tok->link())
|
||||
tok = tok->next()->link();
|
||||
|
||||
else if (Token::Match(tok, "[;{}] %str%") || Token::Match(tok, "[;{}] %num%")) {
|
||||
else if (Token::Match(tok, "[;{}] %str%|%num%")) {
|
||||
// No warning if numeric constant is followed by a "." or ","
|
||||
if (Token::Match(tok->next(), "%num% [,.]"))
|
||||
continue;
|
||||
|
@ -2194,6 +2194,18 @@ void CheckOther::checkIncompleteStatement()
|
|||
if (bailout)
|
||||
continue;
|
||||
|
||||
// no warning if this is the last statement in a ({})
|
||||
for (const Token *tok2 = tok->next(); tok2; tok2 = tok2->next()) {
|
||||
if (tok2->str() == "(")
|
||||
tok2 = tok->link();
|
||||
else if (Token::Match(tok2, "[;{}]")) {
|
||||
bailout = Token::simpleMatch(tok2, "; } )");
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (bailout)
|
||||
continue;
|
||||
|
||||
constStatementError(tok->next(), tok->next()->isNumber() ? "numeric" : "string");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1880,6 +1880,9 @@ void Tokenizer::simplifyRoundCurlyParentheses()
|
|||
for (Token *tok = list.front(); tok; tok = tok->next()) {
|
||||
while (Token::Match(tok, "[;{}] ( {") &&
|
||||
Token::simpleMatch(tok->linkAt(2), "} ) ;")) {
|
||||
Token *end = tok->linkAt(2)->tokAt(-3);
|
||||
if (Token::Match(end, "[;{}] %num%|%str% ;"))
|
||||
end->deleteNext(2);
|
||||
tok->linkAt(2)->previous()->deleteNext(3);
|
||||
tok->deleteNext(2);
|
||||
}
|
||||
|
|
|
@ -69,6 +69,7 @@ private:
|
|||
TEST_CASE(cast); // #3009 : (struct Foo *)123.a = 1;
|
||||
TEST_CASE(increment); // #3251 : FP for increment
|
||||
TEST_CASE(cpp11init); // #5493 : int i{1};
|
||||
TEST_CASE(block); // ({ do_something(); 0; })
|
||||
}
|
||||
|
||||
void test1() {
|
||||
|
@ -228,6 +229,13 @@ private:
|
|||
"}");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
|
||||
void block() {
|
||||
check("void f() {\n"
|
||||
" ({ do_something(); 0; });\n"
|
||||
"}");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
};
|
||||
|
||||
REGISTER_TEST(TestIncompleteStatement)
|
||||
|
|
Loading…
Reference in New Issue