Fixed false positive #6679, fixed unit test for #6663.

This commit is contained in:
PKEuS 2015-05-11 13:10:11 +02:00
parent 1ee3620a93
commit 33277c6110
2 changed files with 48 additions and 2 deletions

View File

@ -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();
}

View File

@ -2677,8 +2677,54 @@ private:
" std::set<int> 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<int> 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<int> 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<int> vec;\n"
"};", true);
ASSERT_EQUALS("[test.cpp:6]: (style, inconclusive) Reading from empty STL container 'vec'\n", errout.str());
}
};