Fixed unreachableCode message if a lambda is returned (#6008).

This commit is contained in:
PKEuS 2014-09-01 11:10:42 +02:00
parent 353a9e9a64
commit b5e064e737
2 changed files with 10 additions and 1 deletions

View File

@ -1120,7 +1120,7 @@ void CheckOther::checkUnreachableCode()
else if (Token::Match(tok, "[;{}:] return|throw")) { else if (Token::Match(tok, "[;{}:] return|throw")) {
tok = tok->next(); // tok should point to return or 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() == "(") if (tok2->str() == "(" || tok2->str() == "{")
tok2 = tok2->link(); tok2 = tok2->link();
if (tok2->str() == ";") { if (tok2->str() == ";") {
secondBreak = tok2->next(); secondBreak = tok2->next();

View File

@ -2974,6 +2974,15 @@ private:
" }));\n" " }));\n"
"}", 0, false, false, false, false); "}", 0, false, false, false, false);
ASSERT_EQUALS("", errout.str()); ASSERT_EQUALS("", errout.str());
// #6008
check("static std::function< int ( int, int ) > GetFunctor() {\n"
" return [](int a_, int b_) -> int {\n"
" int sum = a_ + b_;\n"
" return sum;\n"
" };\n"
"}", 0, false, false, false, false);
ASSERT_EQUALS("", errout.str());
} }