diff --git a/lib/programmemory.cpp b/lib/programmemory.cpp index a6db19e64..6c4261eaf 100644 --- a/lib/programmemory.cpp +++ b/lib/programmemory.cpp @@ -1394,7 +1394,7 @@ struct Executor { return execute(tok); }); if (f) { - if (fdepth >= 0) { + if (fdepth >= 0 && !f->isImplicitlyVirtual()) { ProgramMemory functionState; for (std::size_t i = 0; i < args.size(); ++i) { const Variable* const arg = f->getArgumentVar(i); diff --git a/test/teststl.cpp b/test/teststl.cpp index 10a33783c..e743d8e60 100644 --- a/test/teststl.cpp +++ b/test/teststl.cpp @@ -2334,6 +2334,19 @@ private: "}\n"); ASSERT_EQUALS("", errout.str()); + check("struct B { virtual int g() { return 0; } };\n" // #11831 + "struct C {\n" + " int h() const { return b->g(); }\n" + " B* b;\n" + "};\n" + "struct O {\n" + " int f() const;\n" + " std::vector v;\n" + " C c;\n" + "};\n" + "int O::f() const { return v[c.h() - 1]; }\n"); + ASSERT_EQUALS("", errout.str()); + const auto oldSettings = settings; settings.daca = true;