Fixed #7491 (Questionable enumMismatch)

This commit is contained in:
Daniel Marjamäki 2016-05-11 15:33:59 +02:00
parent 3a6e33d58e
commit bf8471e109
2 changed files with 10 additions and 3 deletions

View File

@ -338,16 +338,16 @@ void CheckType::checkEnumMismatch()
}
// Comparing enum variable against mismatching value
else if (tok->isComparisonOp()) {
else if (Token::Match(tok, "==|!=")) {
if (!tok->astOperand1() || !tok->astOperand2())
continue;
const ValueFlow::Value * const v1 = mismatchingValue(tok->astOperand1()->valueType(), tok->astOperand2()->values);
if (v1)
if (v1 && v1->isKnown())
enumMismatchCompareError(tok, *v1);
const ValueFlow::Value * const v2 = mismatchingValue(tok->astOperand2()->valueType(), tok->astOperand1()->values);
if (v2)
if (v2 && v2->isKnown())
enumMismatchCompareError(tok, *v2);
}
}

View File

@ -228,6 +228,13 @@ private:
" if (5==abc) {}\n"
"}", &settings);
ASSERT_EQUALS("[test.cpp:3]: (style) Comparing mismatching value 5 with enum variable.\n", errout.str());
check("enum ABC {NEG1=-2,NEG2=-1,POS1=1,POS2=2};\n" // #7491
"void f(enum ABC abc) {\n"
" if (abc>0) {}\n"
"}", &settings);
ASSERT_EQUALS("", errout.str());
}
};