Skip to content

Commit b8f80a9

Browse files
Fix #13064 FP derefInvalidIteratorRedundantCheck for initializer_list (regression) (danmar#6768)
1 parent a7dcc70 commit b8f80a9

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

lib/forwardanalyzer.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -611,10 +611,8 @@ namespace {
611611
} else if (!tok->variable() && (Token::Match(tok, "%name% :") || tok->str() == "case")) {
612612
if (!analyzer->lowerToPossible())
613613
return Break(Analyzer::Terminate::Bail);
614-
} else if (tok->link() && tok->str() == "}") {
614+
} else if (tok->link() && tok->str() == "}" && tok == tok->scope()->bodyEnd) { // might be an init list
615615
const Scope* scope = tok->scope();
616-
if (!scope)
617-
return Break();
618616
if (contains({Scope::eDo, Scope::eFor, Scope::eWhile, Scope::eIf, Scope::eElse, Scope::eSwitch}, scope->type)) {
619617
const bool inElse = scope->type == Scope::eElse;
620618
const bool inDoWhile = scope->type == Scope::eDo;

test/teststl.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5132,6 +5132,18 @@ class TestStl : public TestFixture {
51325132
" }\n"
51335133
"}\n");
51345134
ASSERT_EQUALS("", errout_str()); // don't crash
5135+
5136+
check("void f(int);\n" // #13064
5137+
"void g() {\n"
5138+
" std::vector<int> v{ 0 };\n"
5139+
" auto it = std::find(v.begin(), v.end(), 0);\n"
5140+
" if (it == v.end()) {\n"
5141+
" f({});\n"
5142+
" it = v.begin();\n"
5143+
" }\n"
5144+
" *it;\n"
5145+
"}\n");
5146+
ASSERT_EQUALS("", errout_str());
51355147
}
51365148

51375149
void dereferenceInvalidIterator2() {

0 commit comments

Comments
 (0)