From 33277c611083b6092c3ba33624059287cc278f9a Mon Sep 17 00:00:00 2001 From: PKEuS Date: Mon, 11 May 2015 13:10:11 +0200 Subject: [PATCH] Fixed false positive #6679, fixed unit test for #6663. --- lib/checkstl.cpp | 2 +- test/teststl.cpp | 48 +++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 48 insertions(+), 2 deletions(-) diff --git a/lib/checkstl.cpp b/lib/checkstl.cpp index 200b9cfea..94f572abf 100644 --- a/lib/checkstl.cpp +++ b/lib/checkstl.cpp @@ -1584,7 +1584,7 @@ void CheckStl::readingEmptyStlContainer() else readingEmptyStlContainer_parseUsage(tok2, false, empty_nonmap, true); } - } else if (Token::Match(tok, "do|}")) { + } else if (Token::Match(tok, "do|}|break|case")) { empty_map.clear(); empty_nonmap.clear(); } diff --git a/test/teststl.cpp b/test/teststl.cpp index bd0458a9f..9e50413a4 100644 --- a/test/teststl.cpp +++ b/test/teststl.cpp @@ -2677,8 +2677,54 @@ private: " std::set container;\n" " while (container.size() < 5)\n" " container.insert(22);\n" - "}"); + "}", true); ASSERT_EQUALS("", errout.str()); + + // #6679 + check("class C {\n" + " C() {\n" + " switch (ret) {\n" + " case 1:\n" + " vec.clear();\n" + " break;\n" + " case 2:\n" + " if (vec.empty())\n" + " ;\n" + " break;\n" + " }\n" + " }\n" + " std::vector vec;\n" + "};", true); + ASSERT_EQUALS("", errout.str()); + + check("class C {\n" + " C() {\n" + " switch (ret) {\n" + " case 1:\n" + " vec.clear();\n" + " case 2:\n" + " if (vec.empty())\n" + " ;\n" + " break;\n" + " }\n" + " }\n" + " std::vector vec;\n" + "};", true); + ASSERT_EQUALS("", errout.str()); + + check("class C {\n" + " C() {\n" + " switch (ret) {\n" + " case 1:\n" + " vec.clear();\n" + " if (vec.empty())\n" + " ;\n" + " break;\n" + " }\n" + " }\n" + " std::vector vec;\n" + "};", true); + ASSERT_EQUALS("[test.cpp:6]: (style, inconclusive) Reading from empty STL container 'vec'\n", errout.str()); } };