Skip to content

Commit

Permalink
Fix #13064 FP derefInvalidIteratorRedundantCheck for initializer_list…
Browse files Browse the repository at this point in the history
… (regression) (#6768)
  • Loading branch information
chrchr-github committed Sep 3, 2024
1 parent a7dcc70 commit b8f80a9
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
4 changes: 1 addition & 3 deletions lib/forwardanalyzer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -611,10 +611,8 @@ namespace {
} else if (!tok->variable() && (Token::Match(tok, "%name% :") || tok->str() == "case")) {
if (!analyzer->lowerToPossible())
return Break(Analyzer::Terminate::Bail);
} else if (tok->link() && tok->str() == "}") {
} else if (tok->link() && tok->str() == "}" && tok == tok->scope()->bodyEnd) { // might be an init list
const Scope* scope = tok->scope();
if (!scope)
return Break();
if (contains({Scope::eDo, Scope::eFor, Scope::eWhile, Scope::eIf, Scope::eElse, Scope::eSwitch}, scope->type)) {
const bool inElse = scope->type == Scope::eElse;
const bool inDoWhile = scope->type == Scope::eDo;
Expand Down
12 changes: 12 additions & 0 deletions test/teststl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5132,6 +5132,18 @@ class TestStl : public TestFixture {
" }\n"
"}\n");
ASSERT_EQUALS("", errout_str()); // don't crash

check("void f(int);\n" // #13064
"void g() {\n"
" std::vector<int> v{ 0 };\n"
" auto it = std::find(v.begin(), v.end(), 0);\n"
" if (it == v.end()) {\n"
" f({});\n"
" it = v.begin();\n"
" }\n"
" *it;\n"
"}\n");
ASSERT_EQUALS("", errout_str());
}

void dereferenceInvalidIterator2() {
Expand Down

0 comments on commit b8f80a9

Please sign in to comment.