Skip to content

Commit

Permalink
Fix #12757 FP knownEmptyContainer with template specialization (regre…
Browse files Browse the repository at this point in the history
…ssion) (#6434)
  • Loading branch information
chrchr-github authored May 25, 2024
1 parent 912934e commit a858a0b
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/valueflow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2205,6 +2205,8 @@ static Analyzer::Result valueFlowForward(Token* startToken,
const Function* f = Scope::nestedInFunction(startToken->scope());
if (f && f->functionScope)
endToken = f->functionScope->bodyEnd;
if (!endToken && exprTok && exprTok->variable() && !exprTok->variable()->isLocal())
endToken = startToken->scope()->bodyEnd;
return valueFlowForward(startToken, endToken, exprTok, std::move(v), tokenlist, errorLogger, settings, loc);
}

Expand Down
15 changes: 15 additions & 0 deletions test/teststl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6738,6 +6738,21 @@ class TestStl : public TestFixture {
"}\n",
true);
ASSERT_EQUALS("", errout_str());

check("struct S {\n" // #12757
" template<class T = int>\n"
" void clear() {}\n"
" template<class T = int>\n"
" std::vector<T> get() const { return {}; }\n"
" std::vector<int> m;\n"
"};\n"
"template<> void S::clear() { m.clear(); }\n"
"template<> std::vector<int> S::get() const {\n"
" for (const auto& i : m) {}\n"
" return {};\n"
"}\n",
true);
ASSERT_EQUALS("", errout_str());
}

void checkMutexes() {
Expand Down

0 comments on commit a858a0b

Please sign in to comment.