diff --git a/lib/valueflow.cpp b/lib/valueflow.cpp index b6cd25a15..6b79d75d7 100644 --- a/lib/valueflow.cpp +++ b/lib/valueflow.cpp @@ -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; } diff --git a/test/teststl.cpp b/test/teststl.cpp index 105e7c4f4..ff0c69fde 100644 --- a/test/teststl.cpp +++ b/test/teststl.cpp @@ -311,6 +311,13 @@ private: " ++abc[s];\n" "}"); ASSERT_EQUALS("", errout.str()); + + checkNormal("void f() {\n" + " static const int N = 4;\n" + " std::array x;\n" + " x[0] = 0;\n" + "}\n"); + ASSERT_EQUALS("", errout.str()); } void outOfBoundsIndexExpression() {