Fix findEnumerator() with nested enum (refs #10045) (#5454)

This commit is contained in:
chrchr-github 2023-09-18 12:09:59 +02:00 committed by GitHub
parent 640b561633
commit 10c1ac977c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 32 additions and 7 deletions

View File

@ -5050,9 +5050,13 @@ const Enumerator * SymbolDatabase::findEnumerator(const Token * tok, std::set<st
else { else {
// FIXME search base class here // FIXME search base class here
const Scope* temp{};
if (scope->functionOf && (temp = scope->functionOf->findRecordInNestedList(tok1->str()))) {
scope = temp;
} else {
// find first scope // find first scope
while (scope && scope->nestedIn) { while (scope && scope->nestedIn) {
const Scope * temp = scope->nestedIn->findRecordInNestedList(tok1->str()); temp = scope->nestedIn->findRecordInNestedList(tok1->str());
if (temp) { if (temp) {
scope = temp; scope = temp;
break; break;
@ -5060,6 +5064,7 @@ const Enumerator * SymbolDatabase::findEnumerator(const Token * tok, std::set<st
scope = scope->nestedIn; scope = scope->nestedIn;
} }
} }
}
if (scope) { if (scope) {
tok1 = tok1->tokAt(2); tok1 = tok1->tokAt(2);

View File

@ -389,6 +389,7 @@ private:
TEST_CASE(enum12); TEST_CASE(enum12);
TEST_CASE(enum13); TEST_CASE(enum13);
TEST_CASE(enum14); TEST_CASE(enum14);
TEST_CASE(enum15);
TEST_CASE(sizeOfType); TEST_CASE(sizeOfType);
@ -5825,6 +5826,25 @@ private:
ASSERT_EQUALS(f->valueType()->type, ValueType::Type::INT); ASSERT_EQUALS(f->valueType()->type, ValueType::Type::INT);
} }
void enum15() {
GET_SYMBOL_DB("struct S {\n"
" S();\n"
" enum E { E0 };\n"
"};\n"
"S::S() {\n"
" E e = E::E0;\n"
"}\n");
ASSERT(db != nullptr);
auto it = db->scopeList.begin();
std::advance(it, 2);
const Enumerator* E0 = it->findEnumerator("E0");
ASSERT(E0 && E0->value_known && E0->value == 0);
std::advance(it, 1);
const Token* const e = Token::findsimplematch(tokenizer.tokens(), "E0 ;");
ASSERT(e && e->enumerator());
ASSERT_EQUALS(E0, e->enumerator());
}
void sizeOfType() { void sizeOfType() {
// #7615 - crash in Symboldatabase::sizeOfType() // #7615 - crash in Symboldatabase::sizeOfType()
GET_SYMBOL_DB("enum e;\n" GET_SYMBOL_DB("enum e;\n"