Skip to content

Commit

Permalink
Fix #12585 debug: valueFlowBailoutIncompleteVar with enum value named…
Browse files Browse the repository at this point in the history
… like an unrelated parameter (danmar#6233)
  • Loading branch information
chrchr-github committed Apr 4, 2024
1 parent 5ac87cc commit 8d2c386
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
7 changes: 3 additions & 4 deletions lib/symboldatabase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5250,10 +5250,6 @@ const Enumerator * SymbolDatabase::findEnumerator(const Token * tok, std::set<st
return nullptr;

const std::string& tokStr = tok->str();

if (tokensThatAreNotEnumeratorValues.find(tokStr) != tokensThatAreNotEnumeratorValues.end())
return nullptr;

const Scope* scope = tok->scope();

// check for qualified name
Expand Down Expand Up @@ -5314,6 +5310,9 @@ const Enumerator * SymbolDatabase::findEnumerator(const Token * tok, std::set<st
}
} else { // unqualified name

if (tokensThatAreNotEnumeratorValues.find(tokStr) != tokensThatAreNotEnumeratorValues.end())
return nullptr;

if (tok->scope()->type == Scope::eGlobal) {
const Token* astTop = tok->astTop();
if (Token::simpleMatch(astTop, ":") && Token::simpleMatch(astTop->astOperand1(), "(")) { // ctor init list
Expand Down
17 changes: 17 additions & 0 deletions test/testsymboldatabase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6367,6 +6367,23 @@ class TestSymbolDatabase : public TestFixture {
ASSERT(e && e->enumerator());
ASSERT_EQUALS(E1, e->enumerator());
}
{
GET_SYMBOL_DB("enum class E { inc };\n" // #12585
"struct C {\n"
" void f1();\n"
" bool f2(bool inc);\n"
"};\n"
"void C::f1() { const E e = E::inc; }\n"
"void C::f2(bool inc) { return false; }\n");
ASSERT(db != nullptr);
auto it = db->scopeList.begin();
std::advance(it, 1);
const Enumerator* inc = it->findEnumerator("inc");
ASSERT(inc && inc->value_known && inc->value == 0);
const Token* const i = Token::findsimplematch(tokenizer.tokens(), "inc ;");
ASSERT(i && i->enumerator());
ASSERT_EQUALS(inc, i->enumerator());
}
}

void enum17() {
Expand Down

0 comments on commit 8d2c386

Please sign in to comment.