From 4706bf9196f019840930e2b1e783c1f9879d3b85 Mon Sep 17 00:00:00 2001 From: chrchr Date: Fri, 15 Mar 2024 19:14:28 +0100 Subject: [PATCH 1/2] Fix FP truncLongCastAssignment on Windows --- lib/checktype.cpp | 5 ++++- test/testtype.cpp | 5 +++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/checktype.cpp b/lib/checktype.cpp index 0cc91ac8976..df30f929601 100644 --- a/lib/checktype.cpp +++ b/lib/checktype.cpp @@ -299,7 +299,7 @@ void CheckType::signConversionError(const Token *tok, const ValueFlow::Value *ne //--------------------------------------------------------------------------- // Checking for long cast of int result const long x = var1 * var2; //--------------------------------------------------------------------------- -static bool checkTypeCombination(const ValueType& src, const ValueType& tgt, const Settings& settings) +static bool checkTypeCombination(ValueType src, ValueType tgt, const Settings& settings) { static const std::pair typeCombinations[] = { { ValueType::Type::INT, ValueType::Type::LONG }, @@ -310,6 +310,9 @@ static bool checkTypeCombination(const ValueType& src, const ValueType& tgt, con { ValueType::Type::DOUBLE, ValueType::Type::LONGDOUBLE }, }; + src.reference = Reference::None; + tgt.reference = Reference::None; + const std::size_t sizeSrc = ValueFlow::getSizeOf(src, settings); const std::size_t sizeTgt = ValueFlow::getSizeOf(tgt, settings); if (!(sizeSrc > 0 && sizeTgt > 0 && sizeSrc < sizeTgt)) diff --git a/test/testtype.cpp b/test/testtype.cpp index 801cd599191..285dc298ff3 100644 --- a/test/testtype.cpp +++ b/test/testtype.cpp @@ -405,6 +405,11 @@ class TestType : public TestFixture { " U u;\n" "};\n", settings); ASSERT_EQUALS("", errout_str()); // don't crash + + check("void f(long& r, long i) {\n" + " r = 1 << i;\n" + "}\n", settings); + ASSERT_EQUALS("", errout_str()); } void longCastReturn() { From bd5503a08947a9e66f3d37adf7c258e0ace9b4f3 Mon Sep 17 00:00:00 2001 From: chrchr-github Date: Fri, 15 Mar 2024 20:26:51 +0100 Subject: [PATCH 2/2] Fix --- test/testtype.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/testtype.cpp b/test/testtype.cpp index 285dc298ff3..785131a6b6d 100644 --- a/test/testtype.cpp +++ b/test/testtype.cpp @@ -408,7 +408,7 @@ class TestType : public TestFixture { check("void f(long& r, long i) {\n" " r = 1 << i;\n" - "}\n", settings); + "}\n", settingsWin); ASSERT_EQUALS("", errout_str()); }