Fix issue 9202: False positive: std::array, size is a constant (#2132)

This commit is contained in:
Paul Fultz II 2019-09-01 02:44:34 -05:00 committed by Daniel Marjamäki
parent 717aa826d8
commit 121093658d
2 changed files with 9 additions and 2 deletions

View File

@ -5365,8 +5365,8 @@ static void valueFlowContainerSize(TokenList *tokenlist, SymbolDatabase* symbold
continue;
ValueFlow::Value value(0);
if (var->valueType()->container->size_templateArgNo >= 0) {
if (var->dimensions().size() == 1 && var->dimensions().front().known)
value.intvalue = var->dimensions().front().num;
if (var->dimensions().size() == 1 && var->dimensions().front().tok && var->dimensions().front().tok->hasKnownIntValue())
value.intvalue = var->dimensions().front().tok->getKnownIntValue();
else
continue;
}

View File

@ -311,6 +311,13 @@ private:
" ++abc[s];\n"
"}");
ASSERT_EQUALS("", errout.str());
checkNormal("void f() {\n"
" static const int N = 4;\n"
" std::array<int, N> x;\n"
" x[0] = 0;\n"
"}\n");
ASSERT_EQUALS("", errout.str());
}
void outOfBoundsIndexExpression() {