Fixed #4227 (False positive: Comparison of a boolean with an integer (double dResult=false))

This commit is contained in:
Daniel Marjamäki 2012-11-29 09:29:25 +01:00
parent 509721d6d0
commit 3372657a07
2 changed files with 12 additions and 0 deletions

View File

@ -6050,6 +6050,11 @@ bool Tokenizer::simplifyKnownVariablesGetData(unsigned int varid, Token **_tok2,
value += ".0";
}
// float variable: convert true/false to 1.0 / 0.0
else if (tok2->tokAt(2)->isBoolean() && floatvar) {
value = (value == "true") ? "1.0" : "0.0";
}
if (Token::simpleMatch(tok2->next(), "= &"))
tok2 = tok2->tokAt(3);

View File

@ -2708,6 +2708,13 @@ private:
const char expected[] = "void f ( ) {\n\nx ( 0.25 ) ;\n}";
ASSERT_EQUALS(expected, tokenizeAndStringify(code,true));
// Ticket #4227
const char code2[] = "double f() {"
" double a = false;"
" return a;"
"}";
ASSERT_EQUALS("double f ( ) { return 0.0 ; }", tokenizeAndStringify(code2,true));
}
void simplifyKnownVariablesFunctionCalls() {