From 3372657a07b328987d90919e80fd56e1a1c771ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Thu, 29 Nov 2012 09:29:25 +0100 Subject: [PATCH] Fixed #4227 (False positive: Comparison of a boolean with an integer (double dResult=false)) --- lib/tokenize.cpp | 5 +++++ test/testtokenize.cpp | 7 +++++++ 2 files changed, 12 insertions(+) diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 44e856b10..c9992ddee 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -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); diff --git a/test/testtokenize.cpp b/test/testtokenize.cpp index f34053068..13413a4aa 100644 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -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() {