diff --git a/lib/symboldatabase.cpp b/lib/symboldatabase.cpp index b601689f4..97f644f4c 100644 --- a/lib/symboldatabase.cpp +++ b/lib/symboldatabase.cpp @@ -6414,8 +6414,12 @@ void SymbolDatabase::setValueType(Token* tok, const ValueType& valuetype, Source if (it != typeScope->varlist.end()) var = &*it; } - if (var) + if (var) { setValueType(parent, *var); + return; + } + if (const Enumerator* enu = parent->astOperand2()->enumerator()) + setValueType(parent, *enu); return; } diff --git a/test/testsymboldatabase.cpp b/test/testsymboldatabase.cpp index 8c2bec6bd..4171f68a7 100644 --- a/test/testsymboldatabase.cpp +++ b/test/testsymboldatabase.cpp @@ -384,6 +384,7 @@ private: TEST_CASE(enum10); // #11001 TEST_CASE(enum11); TEST_CASE(enum12); + TEST_CASE(enum13); TEST_CASE(sizeOfType); @@ -5701,6 +5702,23 @@ private: ASSERT_EQUALS(e->enumerator(), E0); } + void enum13() { + GET_SYMBOL_DB("struct S { enum E { E0, E1 }; };\n" + "void f(bool b) {\n" + " auto e = b ? S::E0 : S::E1;\n" + "}\n"); + ASSERT(db != nullptr); + auto it = db->scopeList.begin(); + std::advance(it, 2); + const Enumerator* E1 = it->findEnumerator("E1"); + ASSERT(E1 && E1->value_known); + ASSERT_EQUALS(E1->value, 1); + const Token* const a = Token::findsimplematch(tokenizer.tokens(), "auto"); + ASSERT(a && a->valueType()); + TODO_ASSERT(E1->scope == a->valueType()->typeScope); + ASSERT_EQUALS(a->valueType()->type, ValueType::INT); + } + void sizeOfType() { // #7615 - crash in Symboldatabase::sizeOfType() GET_SYMBOL_DB("enum e;\n"