Skip to content

Commit eea05df

Browse files
Fix #13121 FP knownEmptyContainer for static variable (danmar#6971)
1 parent 4f44a5a commit eea05df

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

lib/valueflow.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6599,7 +6599,7 @@ static void valueFlowContainerSize(const TokenList& tokenlist,
65996599
}
66006600
for (const ValueFlow::Value& value : values)
66016601
setTokenValue(tok, value, settings);
6602-
} else if (Token::Match(tok, "%name%|;|{|}|> %var% =") && Token::Match(tok->tokAt(2)->astOperand2(), "[({]") &&
6602+
} else if (Token::Match(tok, ";|{|} %var% =") && Token::Match(tok->tokAt(2)->astOperand2(), "[({]") &&
66036603
// init list
66046604
((tok->tokAt(2) == tok->tokAt(2)->astOperand2()->astParent() && !tok->tokAt(2)->astOperand2()->astOperand2() && tok->tokAt(2)->astOperand2()->str() == "{") ||
66056605
// constructor

test/teststl.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6792,6 +6792,14 @@ class TestStl : public TestFixture {
67926792
"}\n",
67936793
true);
67946794
ASSERT_EQUALS("", errout_str());
6795+
6796+
check("void f(bool b) {\n" // #13121
6797+
" static std::string s = {};\n"
6798+
" for (auto c : s) {}\n"
6799+
" if (b)\n"
6800+
" s += \'a\';\n"
6801+
"}\n", true);
6802+
ASSERT_EQUALS("", errout_str());
67956803
}
67966804

67976805
void checkMutexes() {

0 commit comments

Comments
 (0)