From a5773eb62c1ec24fc4c8a2e0a1568113eac1cd06 Mon Sep 17 00:00:00 2001 From: chrchr Date: Mon, 24 Jul 2023 15:05:35 +0200 Subject: [PATCH] Remove const requirement --- lib/checktype.cpp | 1 - test/testtype.cpp | 6 ++++++ 2 files changed, 6 insertions(+), 1 deletion(-) 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"