From b345c430fe5d4d21e25d6e29a0654c085054fea2 Mon Sep 17 00:00:00 2001 From: PKEuS Date: Sun, 7 May 2017 08:15:58 +0200 Subject: [PATCH] CheckStl::readingEmptyStlContainer(): Skip over lambdas (#8055) --- lib/checkstl.cpp | 3 ++- test/teststl.cpp | 12 ++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) 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()); } };