CheckStl::readingEmptyStlContainer(): Skip over lambdas (#8055)

This commit is contained in:
PKEuS 2017-05-07 08:15:58 +02:00
parent c1cdcc158f
commit b345c430fe
2 changed files with 14 additions and 1 deletions

View File

@ -1551,7 +1551,8 @@ void CheckStl::readingEmptyStlContainer()
} }
} else if (Token::Match(tok, "do|}|break|case")) { } else if (Token::Match(tok, "do|}|break|case")) {
emptyContainer.clear(); emptyContainer.clear();
} } else if (tok->str() == "{" && tok->next()->scope()->type == Scope::eLambda)
tok = tok->link();
if (!tok->varId()) if (!tok->varId())
continue; continue;

View File

@ -3019,6 +3019,18 @@ private:
" it = test.end();\n" " it = test.end();\n"
"}"); "}");
ASSERT_EQUALS("", errout.str()); ASSERT_EQUALS("", errout.str());
// #8055
check("int main() {\n"
" std::string str;\n"
" auto l = [&]() {\n"
" if (str[0] == 'A')\n"
" std::cout << \"!\";\n"
" }\n"
" str = \"A\";\n"
" l();\n"
"}");
ASSERT_EQUALS("", errout.str());
} }
}; };