Fixed #7493 (enumMismatch on Enum declaration)

This commit is contained in:
Daniel Marjamäki 2016-05-12 11:46:08 +02:00
parent 97bbb7da0d
commit 613311cc57
2 changed files with 11 additions and 1 deletions

View File

@ -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<ValueFlow::Value>::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;
}

View File

@ -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() {