Skip to content

Commit 7211458

Browse files
Fix FP truncLongCastAssignment on Windows (f'up to #11953) (danmar#6135)
1 parent 63eac64 commit 7211458

2 files changed

Lines changed: 9 additions & 1 deletion

File tree

lib/checktype.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,7 @@ void CheckType::signConversionError(const Token *tok, const ValueFlow::Value *ne
299299
//---------------------------------------------------------------------------
300300
// Checking for long cast of int result const long x = var1 * var2;
301301
//---------------------------------------------------------------------------
302-
static bool checkTypeCombination(const ValueType& src, const ValueType& tgt, const Settings& settings)
302+
static bool checkTypeCombination(ValueType src, ValueType tgt, const Settings& settings)
303303
{
304304
static const std::pair<ValueType::Type, ValueType::Type> typeCombinations[] = {
305305
{ ValueType::Type::INT, ValueType::Type::LONG },
@@ -310,6 +310,9 @@ static bool checkTypeCombination(const ValueType& src, const ValueType& tgt, con
310310
{ ValueType::Type::DOUBLE, ValueType::Type::LONGDOUBLE },
311311
};
312312

313+
src.reference = Reference::None;
314+
tgt.reference = Reference::None;
315+
313316
const std::size_t sizeSrc = ValueFlow::getSizeOf(src, settings);
314317
const std::size_t sizeTgt = ValueFlow::getSizeOf(tgt, settings);
315318
if (!(sizeSrc > 0 && sizeTgt > 0 && sizeSrc < sizeTgt))

test/testtype.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -405,6 +405,11 @@ class TestType : public TestFixture {
405405
" U u;\n"
406406
"};\n", settings);
407407
ASSERT_EQUALS("", errout_str()); // don't crash
408+
409+
check("void f(long& r, long i) {\n"
410+
" r = 1 << i;\n"
411+
"}\n", settingsWin);
412+
ASSERT_EQUALS("", errout_str());
408413
}
409414

410415
void longCastReturn() {

0 commit comments

Comments
 (0)