diff --git a/lib/checktype.cpp b/lib/checktype.cpp index e3e0db947..6dea55dc6 100644 --- a/lib/checktype.cpp +++ b/lib/checktype.cpp @@ -366,7 +366,8 @@ void CheckType::longCastAssignError(const Token *tok) reportError(tok, Severity::style, "truncLongCastAssignment", - "possible loss of information, int result is assigned to long variable"); + "int result is assigned to long variable. If the variable is long to avoid loss of information, then you have loss of information.\n" + "int result is assigned to long variable. If the variable is long to avoid loss of information, then there is loss of information. To avoid loss of information you must cast a calculation operand to long, for example 'l = a * b;' => 'l = (long)a * b;'."); } void CheckType::longCastReturnError(const Token *tok) @@ -374,5 +375,6 @@ void CheckType::longCastReturnError(const Token *tok) reportError(tok, Severity::style, "truncLongCastReturn", - "possible loss of information, int result is returned as long value"); + "int result is returned as long value. If the return value is long to avoid loss of information, then you have loss of information.\n" + "int result is returned as long value. If the return value is long to avoid loss of information, then there is loss of information. To avoid loss of information you must cast a calculation operand to long, for example 'return a*b;' => 'return (long)a*b'."); } diff --git a/test/testtype.cpp b/test/testtype.cpp index d5c1da84d..503156fbf 100644 --- a/test/testtype.cpp +++ b/test/testtype.cpp @@ -146,7 +146,7 @@ private: " const long ret = x * y;\n" " return ret;\n" "}\n", &settings); - ASSERT_EQUALS("[test.cpp:2]: (style) possible loss of information, int result is assigned to long variable\n", errout.str()); + 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()); // typedef check("long f(int x, int y) {\n" @@ -170,7 +170,7 @@ private: check("long f(int x, int y) {\n" " return x * y;\n" "}\n", &settings); - ASSERT_EQUALS("[test.cpp:2]: (style) possible loss of information, int result is returned as long value\n", errout.str()); + ASSERT_EQUALS("[test.cpp:2]: (style) int result is returned as long value. If the return value is long to avoid loss of information, then you have loss of information.\n", errout.str()); // typedef check("size_t f(int x, int y) {\n"