diff --git a/lib/symboldatabase.cpp b/lib/symboldatabase.cpp index 98f9fad21..33e769012 100644 --- a/lib/symboldatabase.cpp +++ b/lib/symboldatabase.cpp @@ -1278,6 +1278,7 @@ void SymbolDatabase::createSymbolDatabaseEnums() continue; MathLib::bigint value = 0; + bool prev_enum_is_known = true; for (Enumerator & enumerator : it->enumeratorList) { // look for initialization tokens that can be converted to enumerators and convert them @@ -1304,11 +1305,13 @@ void SymbolDatabase::createSymbolDatabaseEnums() enumerator.value = rhs->values().front().intvalue; enumerator.value_known = true; value = enumerator.value + 1; - } + prev_enum_is_known = true; + } else + prev_enum_is_known = false; } // not initialized so use default value - else { + else if (prev_enum_is_known) { enumerator.value = value++; enumerator.value_known = true; } diff --git a/test/testsymboldatabase.cpp b/test/testsymboldatabase.cpp index ac0054d2e..85f6774ca 100644 --- a/test/testsymboldatabase.cpp +++ b/test/testsymboldatabase.cpp @@ -336,6 +336,7 @@ private: TEST_CASE(enum5); TEST_CASE(enum6); TEST_CASE(enum7); + TEST_CASE(enum8); TEST_CASE(sizeOfType); @@ -5008,6 +5009,31 @@ private: TEST(settings1.sizeof_long_long); } + void enum8() { + GET_SYMBOL_DB("enum E { X0 = x, X1, X2 = 2, X3, X4 = y, X5 };\n"); + ASSERT(db != nullptr); + const Enumerator *X0 = db->scopeList.back().findEnumerator("X0"); + ASSERT(X0); + ASSERT(!X0->value_known); + const Enumerator *X1 = db->scopeList.back().findEnumerator("X1"); + ASSERT(X1); + ASSERT(!X1->value_known); + const Enumerator *X2 = db->scopeList.back().findEnumerator("X2"); + ASSERT(X2); + ASSERT(X2->value_known); + ASSERT_EQUALS(X2->value, 2); + const Enumerator *X3 = db->scopeList.back().findEnumerator("X3"); + ASSERT(X3); + ASSERT(X3->value_known); + ASSERT_EQUALS(X3->value, 3); + const Enumerator *X4 = db->scopeList.back().findEnumerator("X4"); + ASSERT(X4); + ASSERT(!X4->value_known); + const Enumerator *X5 = db->scopeList.back().findEnumerator("X5"); + ASSERT(X5); + ASSERT(!X5->value_known); + } + void sizeOfType() { // #7615 - crash in Symboldatabase::sizeOfType() GET_SYMBOL_DB("enum e;\n"