diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 4c0ef597b..44258415d 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -6525,10 +6525,8 @@ bool Tokenizer::simplifyKnownVariablesGetData(unsigned int varid, Token **_tok2, valueIsPointer = true; } - // float value should contain a "." - else if (tok2->tokAt(2)->isNumber() && - floatvar && - value.find(".") == std::string::npos) { + // Add a '.0' to a decimal value and therefore convert it to an floating point number. + else if (MathLib::isDec(tok2->tokAt(2)->str()) && floatvar) { value += ".0"; } diff --git a/test/testtokenize.cpp b/test/testtokenize.cpp index cd4bb4dd5..f95460d9c 100644 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -3179,6 +3179,19 @@ private: " return a;" "}"; ASSERT_EQUALS("double f ( ) { return 0.0 ; }", tokenizeAndStringify(code2,true)); + + // Ticket #5485 + const char code3[] = "void f() {" + " double a = 1e+007;\n" + " std::cout << a;\n" + "}"; + ASSERT_EQUALS("void f ( ) {\nstd :: cout << 1e+007 ;\n}", tokenizeAndStringify(code3,true)); + + const char code4[] = "void f() {" + " double a = 1;\n" + " std::cout << a;\n" + "}"; + ASSERT_EQUALS("void f ( ) {\nstd :: cout << 1.0 ;\n}", tokenizeAndStringify(code4,true)); } void simplifyKnownVariablesFunctionCalls() {