Skip to content

Commit

Permalink
Set enum ValueType for ::
Browse files Browse the repository at this point in the history
  • Loading branch information
chrchr-github committed Aug 7, 2023
1 parent 5ff8955 commit fe034f6
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
6 changes: 5 additions & 1 deletion lib/symboldatabase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
18 changes: 18 additions & 0 deletions test/testsymboldatabase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,7 @@ class TestSymbolDatabase : public TestFixture {
TEST_CASE(enum10); // #11001
TEST_CASE(enum11);
TEST_CASE(enum12);
TEST_CASE(enum13);

TEST_CASE(sizeOfType);

Expand Down Expand Up @@ -5701,6 +5702,23 @@ class TestSymbolDatabase : public TestFixture {
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"
Expand Down

0 comments on commit fe034f6

Please sign in to comment.