diff --git a/lib/checktype.cpp b/lib/checktype.cpp index 65162374a69..ad5fb4584da 100644 --- a/lib/checktype.cpp +++ b/lib/checktype.cpp @@ -329,7 +329,6 @@ void CheckType::checkLongCast() rhstype->originalTypeName.empty() && (lhstype->type == ValueType::Type::LONG || lhstype->type == ValueType::Type::LONGLONG) && lhstype->pointer == 0U && - lhstype->constness == 1U && lhstype->originalTypeName.empty() && isSmallerTypeSize(rhstype, lhstype, mTokenizer)) longCastAssignError(tok); diff --git a/test/testtype.cpp b/test/testtype.cpp index 6d003ad7d44..42c30561b0a 100644 --- a/test/testtype.cpp +++ b/test/testtype.cpp @@ -337,6 +337,12 @@ class TestType : public TestFixture { check(code, settingsWin); ASSERT_EQUALS("", errout.str()); + check("long f(int x, int y) {\n" + " long ret = x * y;\n" + " return ret;\n" + "}\n", settings); + ASSERT_EQUALS("[test.cpp:2]: (style) int result is assigned to long variable. If the variable is long to avoid loss of information, then you have loss of information.\n", errout.str()); + check("long f() {\n" " const long long ret = 256 * (1 << 10);\n" " return ret;\n"