Fixed #7925 (False Positive identical condition)

This commit is contained in:
Daniel Marjamäki 2017-02-22 21:13:36 +01:00
parent 6db99d105f
commit a53f14da25
2 changed files with 14 additions and 0 deletions

View File

@ -149,6 +149,14 @@ bool isSameExpression(bool cpp, bool macro, const Token *tok1, const Token *tok2
}
if (macro && (tok1->isExpandedMacro() || tok2->isExpandedMacro()))
return false;
if (tok1->isComplex() != tok2->isComplex())
return false;
if (tok1->isLong() != tok2->isLong())
return false;
if (tok1->isUnsigned() != tok2->isUnsigned())
return false;
if (tok1->isSigned() != tok2->isSigned())
return false;
if (tok1->isName() && tok1->next()->str() == "(" && tok1->str() != "sizeof") {
if (!tok1->function() && !Token::Match(tok1->previous(), ".|::") && pure && !library.isFunctionConst(tok1->str(), true) && !tok1->isAttributeConst() && !tok1->isAttributePure())
return false;

View File

@ -564,6 +564,12 @@ private:
" else if (x == 40) {}\n"
"}");
ASSERT_EQUALS("[test.cpp:3]: (style) Expression is always false because 'else if' condition matches previous condition at line 2.\n", errout.str());
check("void f(int x) {\n"
" if (x == sizeof(double)) {}\n"
" else { if (x == sizeof(long double)) {} }"
"}");
ASSERT_EQUALS("", errout.str());
}
void checkBadBitmaskCheck() {