Fixed #7493 (enumMismatch on Enum declaration)
This commit is contained in:
parent
97bbb7da0d
commit
613311cc57
|
@ -306,12 +306,16 @@ static const ValueFlow::Value *mismatchingValue(const ValueType *enumType, const
|
||||||
if (!enumType || !enumType->typeScope || enumType->typeScope->type != Scope::eEnum)
|
if (!enumType || !enumType->typeScope || enumType->typeScope->type != Scope::eEnum)
|
||||||
return nullptr;
|
return nullptr;
|
||||||
const Scope * const enumScope = enumType->typeScope;
|
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) {
|
for (std::list<ValueFlow::Value>::const_iterator it = values.begin(); it != values.end(); ++it) {
|
||||||
if (it->tokvalue)
|
if (it->tokvalue)
|
||||||
continue;
|
continue;
|
||||||
bool found = false;
|
bool found = false;
|
||||||
for (unsigned int i = 0; i < enumScope->enumeratorList.size(); ++i) {
|
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;
|
found = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
@ -211,6 +211,12 @@ private:
|
||||||
" enum ABC abc = 5;\n"
|
" enum ABC abc = 5;\n"
|
||||||
"}", &settings);
|
"}", &settings);
|
||||||
ASSERT_EQUALS("[test.cpp:3]: (style) Assigning mismatching value 5 to enum variable.\n", errout.str());
|
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() {
|
void enumMismatchCompare() {
|
||||||
|
|
Loading…
Reference in New Issue