Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions lib/valueflow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5377,6 +5377,8 @@ static std::vector<ValueFlow::Value> getInitListSize(const Token* tok,
initList = true;
else if (args.size() == 1 && valueFlowIsSameContainerType(vt, tok->astOperand2(), settings))
initList = false; // copy ctor
else if (args.size() == 2 && (!args[0]->valueType() || !args[1]->valueType())) // might be unknown iterators
initList = false;
}
}
if (!initList)
Expand Down
8 changes: 8 additions & 0 deletions test/testvalueflow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6992,6 +6992,14 @@ class TestValueFlow : public TestFixture {
" if (s.empty()) {}\n"
"}";
ASSERT_EQUALS("", isPossibleContainerSizeValue(tokenValues(code, "s . empty"), 0));

code = "int f(const std::string& str) {\n"
" std::istringstream iss(str);\n"
" std::vector<std::string> v{ std::istream_iterator<std::string>(iss), {} };\n"
" auto x = v.size();\n"
" return x;\n"
"}";
ASSERT_EQUALS(false, testValueOfXKnown(code, 5U, 2));
}

void valueFlowContainerElement()
Expand Down