From 72114589e239d8dca30096dd9de126d8327010a2 Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Wed, 20 Mar 2024 12:42:40 +0100 Subject: [PATCH] Fix FP truncLongCastAssignment on Windows (f'up to #11953) (#6135) --- 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..785131a6b6d 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", settingsWin); + ASSERT_EQUALS("", errout_str()); } void longCastReturn() {