Skip to content

Commit 4bde4d5

Browse files
committed
updated style messages
1 parent ffcf45a commit 4bde4d5

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

lib/checktype.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -366,13 +366,15 @@ void CheckType::longCastAssignError(const Token *tok)
366366
reportError(tok,
367367
Severity::style,
368368
"truncLongCastAssignment",
369-
"possible loss of information, int result is assigned to long variable");
369+
"int result is assigned to long variable. If the variable is long to avoid loss of information, then you have loss of information.\n"
370+
"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;'.");
370371
}
371372

372373
void CheckType::longCastReturnError(const Token *tok)
373374
{
374375
reportError(tok,
375376
Severity::style,
376377
"truncLongCastReturn",
377-
"possible loss of information, int result is returned as long value");
378+
"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"
379+
"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'.");
378380
}

test/testtype.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ class TestType : public TestFixture {
146146
" const long ret = x * y;\n"
147147
" return ret;\n"
148148
"}\n", &settings);
149-
ASSERT_EQUALS("[test.cpp:2]: (style) possible loss of information, int result is assigned to long variable\n", errout.str());
149+
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());
150150

151151
// typedef
152152
check("long f(int x, int y) {\n"
@@ -170,7 +170,7 @@ class TestType : public TestFixture {
170170
check("long f(int x, int y) {\n"
171171
" return x * y;\n"
172172
"}\n", &settings);
173-
ASSERT_EQUALS("[test.cpp:2]: (style) possible loss of information, int result is returned as long value\n", errout.str());
173+
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());
174174

175175
// typedef
176176
check("size_t f(int x, int y) {\n"

0 commit comments

Comments
 (0)