diff --git a/lib/valueflow.cpp b/lib/valueflow.cpp index 9194186e1..a273749e4 100644 --- a/lib/valueflow.cpp +++ b/lib/valueflow.cpp @@ -1646,6 +1646,8 @@ static void valueFlowFunctionDefaultParameter(TokenList *tokenlist, SymbolDataba const Variable* var = function->getArgumentVar(arg); if (var && var->hasDefault() && Token::Match(var->nameToken(), "%var% = %num%|%str% [,)]")) { const Token* valueTok = var->nameToken()->tokAt(2); + if (valueTok->values.empty()) + continue; const_cast(valueTok)->values.front().defaultArg = true; valueFlowInjectParameter(tokenlist, errorLogger, settings, var, scope, valueTok->values); } diff --git a/test/testvalueflow.cpp b/test/testvalueflow.cpp index fbfd968bd..804fb0add 100644 --- a/test/testvalueflow.cpp +++ b/test/testvalueflow.cpp @@ -62,6 +62,8 @@ private: TEST_CASE(valueFlowForLoop); TEST_CASE(valueFlowSubFunction); TEST_CASE(valueFlowFunctionReturn); + + TEST_CASE(valueFlowFunctionDefaultParameter); } bool testValueOfX(const char code[], unsigned int linenr, int value) { @@ -1422,6 +1424,15 @@ private: "}"; ASSERT_EQUALS(15, valueOfTok(code, "*").intvalue); } + + void valueFlowFunctionDefaultParameter() { + const char *code; + + code = "class continuous_src_time {\n" + " continuous_src_time(std::complex f, double st = 0.0, double et = infinity) {}\n" + "};"; + testValueOfX(code, 2U, 2); // Don't crash (#6494) + } }; REGISTER_TEST(TestValueFlow)