Skip to content

Commit 3529cd6

Browse files
Fix #14036 Assert failure in getParentValueTypes() (#7758)
1 parent 321e50c commit 3529cd6

File tree

2 files changed

+17
-4
lines changed

2 files changed

+17
-4
lines changed

lib/astutils.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -775,10 +775,11 @@ std::vector<ValueType> getParentValueTypes(const Token* tok, const Settings& set
775775
if (scope && scope->numConstructors == 0 && t->derivedFrom.empty() &&
776776
(t->isClassType() || t->isStructType()) && numberOfArguments(ftok) <= scope->varlist.size() &&
777777
!scope->varlist.empty()) {
778-
assert(argn < scope->varlist.size());
779-
auto it = std::next(scope->varlist.cbegin(), argn);
780-
if (it->valueType())
781-
return {*it->valueType()};
778+
if (argn < scope->varlist.size()) {
779+
auto it = std::next(scope->varlist.cbegin(), argn);
780+
if (it->valueType())
781+
return { *it->valueType() };
782+
}
782783
}
783784
}
784785
}

test/testvalueflow.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7980,6 +7980,18 @@ class TestValueFlow : public TestFixture {
79807980
" return (!std::is_reference<decltype(a)>::value);\n"
79817981
"}\n";
79827982
(void)valueOfTok(code, "0");
7983+
7984+
code = "struct S { int a; };\n" // #14036
7985+
"template <typename T>\n"
7986+
"struct U {\n"
7987+
" U() = default;\n"
7988+
" U(int i, int* p) {\n"
7989+
" m = new T(i, p);\n"
7990+
" }\n"
7991+
" T m;\n"
7992+
"};\n"
7993+
"U<S*> u;\n";
7994+
(void)valueOfTok(code, "new");
79837995
}
79847996

79857997
void valueFlowHang() {

0 commit comments

Comments
 (0)