Fix regression: wrong array size (#5194)

This commit is contained in:
chrchr-github 2023-06-26 06:51:01 +02:00 committed by GitHub
parent 9dc38f80c0
commit 7507d400de
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 4 additions and 1 deletions

View File

@ -8801,7 +8801,7 @@ static void valueFlowContainerSize(TokenList* tokenlist,
value.setKnown();
valueFlowForward(containerTok->next(), containerTok, value, tokenlist, settings);
}
} else if (Token::Match(tok->previous(), ">|return (|{") && astIsContainer(tok)) {
} else if (Token::Match(tok->previous(), ">|return (|{") && astIsContainer(tok) && getLibraryContainer(tok)->size_templateArgNo < 0) {
std::vector<ValueFlow::Value> values;
if (Token::simpleMatch(tok, "{")) {
values = getInitListSize(tok, tok->valueType(), settings, true);

View File

@ -6615,6 +6615,9 @@ private:
code = "std::vector<int> f() { return {}; }";
ASSERT_EQUALS("", isKnownContainerSizeValue(tokenValues(code, "{ } ;"), 0));
code = "int f() { auto a = std::array<int, 2>{}; return a[1]; }";
ASSERT_EQUALS("values.size():0", isKnownContainerSizeValue(tokenValues(code, "a ["), 0));
}
void valueFlowContainerElement()