diff --git a/lib/astutils.cpp b/lib/astutils.cpp index 8e6ee974f15..b2656f4d31b 100644 --- a/lib/astutils.cpp +++ b/lib/astutils.cpp @@ -775,10 +775,11 @@ std::vector getParentValueTypes(const Token* tok, const Settings& set if (scope && scope->numConstructors == 0 && t->derivedFrom.empty() && (t->isClassType() || t->isStructType()) && numberOfArguments(ftok) <= scope->varlist.size() && !scope->varlist.empty()) { - assert(argn < scope->varlist.size()); - auto it = std::next(scope->varlist.cbegin(), argn); - if (it->valueType()) - return {*it->valueType()}; + if (argn < scope->varlist.size()) { + auto it = std::next(scope->varlist.cbegin(), argn); + if (it->valueType()) + return { *it->valueType() }; + } } } } diff --git a/test/testvalueflow.cpp b/test/testvalueflow.cpp index c0fc9867df2..fe0ea225b5b 100644 --- a/test/testvalueflow.cpp +++ b/test/testvalueflow.cpp @@ -7980,6 +7980,18 @@ class TestValueFlow : public TestFixture { " return (!std::is_reference::value);\n" "}\n"; (void)valueOfTok(code, "0"); + + code = "struct S { int a; };\n" // #14036 + "template \n" + "struct U {\n" + " U() = default;\n" + " U(int i, int* p) {\n" + " m = new T(i, p);\n" + " }\n" + " T m;\n" + "};\n" + "U u;\n"; + (void)valueOfTok(code, "new"); } void valueFlowHang() {