Fixed #6598 (False positive zerodivcond - cast to double ignored)

This commit is contained in:
Daniel Marjamäki 2015-07-26 22:08:36 +02:00
parent 7cdeb70efa
commit 389aec51ae
3 changed files with 15 additions and 1 deletions

View File

@ -53,6 +53,10 @@ bool astIsFloat(const Token *tok, bool unknown)
return tok->variable()->isFloatingType();
}
// cast
if (Token::Match(tok, "( const| float|double )"))
return true;
if (tok->isOp())
return false;

View File

@ -79,6 +79,7 @@ public:
checkOther.checkCommaSeparatedReturn();
checkOther.checkIgnoredReturnValue();
checkOther.checkRedundantPointerOp();
checkOther.checkZeroDivision();
// --check-library : functions with nonmatching configuration
checkOther.checkLibraryMatchFunctions();
@ -96,7 +97,6 @@ public:
checkOther.checkCastIntToCharAndBack();
checkOther.invalidFunctionUsage();
checkOther.checkZeroDivision();
checkOther.checkMathFunctions();
checkOther.checkMisusedScopedObject();

View File

@ -266,6 +266,16 @@ private:
" cout << 1. / 0;\n"
"}");
ASSERT_EQUALS("", errout.str());
check("void foo() {\n"
" cout << 42 / (double)0;\n"
"}");
ASSERT_EQUALS("", errout.str());
check("void foo() {\n"
" cout << 42 / (float)0;\n"
"}");
ASSERT_EQUALS("", errout.str());
}
void zeroDiv2() {