diff --git a/lib/checktype.cpp b/lib/checktype.cpp index 7bb832622..3c0738c05 100644 --- a/lib/checktype.cpp +++ b/lib/checktype.cpp @@ -306,12 +306,16 @@ static const ValueFlow::Value *mismatchingValue(const ValueType *enumType, const if (!enumType || !enumType->typeScope || enumType->typeScope->type != Scope::eEnum) return nullptr; const Scope * const enumScope = enumType->typeScope; + for (unsigned int i = 0; i < enumScope->enumeratorList.size(); ++i) { + if (!enumScope->enumeratorList[i].value_known) + return nullptr; + } for (std::list::const_iterator it = values.begin(); it != values.end(); ++it) { if (it->tokvalue) continue; bool found = false; for (unsigned int i = 0; i < enumScope->enumeratorList.size(); ++i) { - if (enumScope->enumeratorList[i].value_known && enumScope->enumeratorList[i].value == it->intvalue) { + if (enumScope->enumeratorList[i].value == it->intvalue) { found = true; break; } diff --git a/test/testtype.cpp b/test/testtype.cpp index 86ac3adb7..88a91f102 100644 --- a/test/testtype.cpp +++ b/test/testtype.cpp @@ -211,6 +211,12 @@ private: " enum ABC abc = 5;\n" "}", &settings); ASSERT_EQUALS("[test.cpp:3]: (style) Assigning mismatching value 5 to enum variable.\n", errout.str()); + + check("enum ABC {A=X,B,C};\n" // #7493 => enum constants for ABC has unknown values + "void f() {\n" + " enum ABC abc = 5;\n" + "}", &settings); + ASSERT_EQUALS("", errout.str()); } void enumMismatchCompare() {