diff --git a/lib/checkstl.cpp b/lib/checkstl.cpp index cd101dbb4..524bfbbde 100644 --- a/lib/checkstl.cpp +++ b/lib/checkstl.cpp @@ -1551,7 +1551,8 @@ void CheckStl::readingEmptyStlContainer() } } else if (Token::Match(tok, "do|}|break|case")) { emptyContainer.clear(); - } + } else if (tok->str() == "{" && tok->next()->scope()->type == Scope::eLambda) + tok = tok->link(); if (!tok->varId()) continue; diff --git a/test/teststl.cpp b/test/teststl.cpp index 6607b4176..e42cfb7c4 100644 --- a/test/teststl.cpp +++ b/test/teststl.cpp @@ -3019,6 +3019,18 @@ private: " it = test.end();\n" "}"); 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()); } };