From 8d2c386afff0f37243b05e1032e63ddcb342514e Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Thu, 4 Apr 2024 21:19:56 +0200 Subject: [PATCH] Fix #12585 debug: valueFlowBailoutIncompleteVar with enum value named like an unrelated parameter (#6233) --- lib/symboldatabase.cpp | 7 +++---- test/testsymboldatabase.cpp | 17 +++++++++++++++++ 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/lib/symboldatabase.cpp b/lib/symboldatabase.cpp index a7d7baf23fc..65d47954e4f 100644 --- a/lib/symboldatabase.cpp +++ b/lib/symboldatabase.cpp @@ -5250,10 +5250,6 @@ const Enumerator * SymbolDatabase::findEnumerator(const Token * tok, std::setstr(); - - if (tokensThatAreNotEnumeratorValues.find(tokStr) != tokensThatAreNotEnumeratorValues.end()) - return nullptr; - const Scope* scope = tok->scope(); // check for qualified name @@ -5314,6 +5310,9 @@ const Enumerator * SymbolDatabase::findEnumerator(const Token * tok, std::setscope()->type == Scope::eGlobal) { const Token* astTop = tok->astTop(); if (Token::simpleMatch(astTop, ":") && Token::simpleMatch(astTop->astOperand1(), "(")) { // ctor init list diff --git a/test/testsymboldatabase.cpp b/test/testsymboldatabase.cpp index 01a54720496..a9860efd227 100644 --- a/test/testsymboldatabase.cpp +++ b/test/testsymboldatabase.cpp @@ -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() {