Skip to content

Commit 7507d40

Browse files
Fix regression: wrong array size (#5194)
1 parent 9dc38f8 commit 7507d40

2 files changed

Lines changed: 4 additions & 1 deletion

File tree

lib/valueflow.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8801,7 +8801,7 @@ static void valueFlowContainerSize(TokenList* tokenlist,
88018801
value.setKnown();
88028802
valueFlowForward(containerTok->next(), containerTok, value, tokenlist, settings);
88038803
}
8804-
} else if (Token::Match(tok->previous(), ">|return (|{") && astIsContainer(tok)) {
8804+
} else if (Token::Match(tok->previous(), ">|return (|{") && astIsContainer(tok) && getLibraryContainer(tok)->size_templateArgNo < 0) {
88058805
std::vector<ValueFlow::Value> values;
88068806
if (Token::simpleMatch(tok, "{")) {
88078807
values = getInitListSize(tok, tok->valueType(), settings, true);

test/testvalueflow.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6615,6 +6615,9 @@ class TestValueFlow : public TestFixture {
66156615

66166616
code = "std::vector<int> f() { return {}; }";
66176617
ASSERT_EQUALS("", isKnownContainerSizeValue(tokenValues(code, "{ } ;"), 0));
6618+
6619+
code = "int f() { auto a = std::array<int, 2>{}; return a[1]; }";
6620+
ASSERT_EQUALS("values.size():0", isKnownContainerSizeValue(tokenValues(code, "a ["), 0));
66186621
}
66196622

66206623
void valueFlowContainerElement()

0 commit comments

Comments
 (0)