Fix #11831 FP negativeContainerIndex / wrong return value from virtual function (#5240)

This commit is contained in:
chrchr-github 2023-07-13 20:38:47 +02:00 committed by GitHub
parent 258581ce2e
commit 48dd4dc33e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 1 deletions

View File

@ -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);

View File

@ -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<int> 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;