Fixed #4711: (false positive: Consecutive return...)
This commit is contained in:
parent
2f1050595d
commit
d387e8b770
|
@ -1559,11 +1559,14 @@ void CheckOther::checkUnreachableCode()
|
|||
secondBreak = tok->tokAt(2);
|
||||
else if (Token::Match(tok, "[;{}:] return|throw")) {
|
||||
tok = tok->next(); // tok should point to return or throw
|
||||
for (const Token *tok2 = tok->next(); tok2; tok2 = tok2->next())
|
||||
for (const Token *tok2 = tok->next(); tok2; tok2 = tok2->next()) {
|
||||
if (tok2->str() == "(")
|
||||
tok2 = tok2->link();
|
||||
if (tok2->str() == ";") {
|
||||
secondBreak = tok2->next();
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else if (Token::Match(tok, "goto %any% ;")) {
|
||||
secondBreak = tok->tokAt(3);
|
||||
labelName = tok->next();
|
||||
|
|
|
@ -2776,6 +2776,12 @@ private:
|
|||
" return 1;\n"
|
||||
"}", 0, false, true, false, false);
|
||||
ASSERT_EQUALS("[test.cpp:5]: (style, inconclusive) Consecutive return, break, continue, goto or throw statements are unnecessary.\n", errout.str());
|
||||
|
||||
// #4711 lambda functions
|
||||
check("int f() {\n"
|
||||
" return g([](int x){x+1; return x;});\n"
|
||||
"}", 0, false, false, false, false);
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue