Revert "CheckOther::clarifyStatement: improved message to show what's the 'bad' and the 'good' expression."

This reverts commit f8591f9004.
This commit is contained in:
PKEuS 2012-09-15 20:19:02 +02:00
parent ae7ee5ffd3
commit 9a624576f4
3 changed files with 14 additions and 17 deletions

View File

@ -259,20 +259,17 @@ void CheckOther::clarifyStatement()
break;
}
if (Token::Match(tok, "++|-- [;,]"))
//TODO: change the string in order to remove the excessive spaces between the tokens.
clarifyStatementError(tok,
tok2->next()->stringifyList(tok->tokAt(2)),
"("+tok2->next()->stringifyList(tok)+")"+tok->stringifyList(tok->tokAt(2)));
clarifyStatementError(tok);
}
}
}
}
void CheckOther::clarifyStatementError(const Token *tok, const std::string &expr, const std::string &suggested)
void CheckOther::clarifyStatementError(const Token *tok)
{
reportError(tok, Severity::warning, "clarifyStatement", "Ineffective statement: '" + expr + "'. Did you intend to write '" + suggested + "'?\n"
"A statement like '*expr++;' might not do what you intended. Postfix 'operator++' is executed before 'operator*'. "
"Thus, the dereference is meaningless. Did you intend to write '(*expr)++;'?");
reportError(tok, Severity::warning, "clarifyStatement", "Ineffective statement similar to '*A++;'. Did you intend to write '(*A)++;'?\n"
"A statement like '*A++;' might not do what you intended. Postfix 'operator++' is executed before 'operator*'. "
"Thus, the dereference is meaningless. Did you intend to write '(*A)++;'?");
}
//---------------------------------------------------------------------------

View File

@ -274,7 +274,7 @@ private:
void warningDeadCode(const Token *tok);
void clarifyCalculationError(const Token *tok, const std::string &op);
void clarifyConditionError(const Token *tok, bool assign, bool boolop);
void clarifyStatementError(const Token* tok, const std::string &expr, const std::string &suggested);
void clarifyStatementError(const Token* tok);
void sizeofsizeofError(const Token *tok);
void sizeofCalculationError(const Token *tok, bool inconclusive);
void cstyleCastError(const Token *tok);
@ -377,7 +377,7 @@ private:
c.memsetZeroBytesError(0, "varname");
c.clarifyCalculationError(0, "+");
c.clarifyConditionError(0, true, false);
c.clarifyStatementError(0,"* A ++ ;","(* A)++ ;");
c.clarifyStatementError(0);
c.incorrectStringCompareError(0, "substr", "\"Hello World\"", "12");
c.suspiciousStringCompareError(0, "foo");
c.incorrectStringBooleanError(0, "\"Hello World\"");

View File

@ -4046,28 +4046,28 @@ private:
" *c++;\n"
" return c;\n"
"}");
ASSERT_EQUALS("[test.cpp:2]: (warning) Ineffective statement: '* c ++ ;'. Did you intend to write '(* c)++ ;'?\n", errout.str());
ASSERT_EQUALS("[test.cpp:2]: (warning) Ineffective statement similar to '*A++;'. Did you intend to write '(*A)++;'?\n", errout.str());
check("char* f(char** c) {\n"
" *c[5]--;\n"
" return *c;\n"
"}");
ASSERT_EQUALS("[test.cpp:2]: (warning) Ineffective statement: '* c [ 5 ] -- ;'. Did you intend to write '(* c [ 5 ])-- ;'?\n", errout.str());
ASSERT_EQUALS("[test.cpp:2]: (warning) Ineffective statement similar to '*A++;'. Did you intend to write '(*A)++;'?\n", errout.str());
check("void f(Foo f) {\n"
" *f.a++;\n"
"}");
ASSERT_EQUALS("[test.cpp:2]: (warning) Ineffective statement: '* f . a ++ ;'. Did you intend to write '(* f . a)++ ;'?\n", errout.str());
ASSERT_EQUALS("[test.cpp:2]: (warning) Ineffective statement similar to '*A++;'. Did you intend to write '(*A)++;'?\n", errout.str());
check("void f(Foo f) {\n"
" *f.a[5].v[3]++;\n"
"}");
ASSERT_EQUALS("[test.cpp:2]: (warning) Ineffective statement: '* f . a [ 5 ] . v [ 3 ] ++ ;'. Did you intend to write '(* f . a [ 5 ] . v [ 3 ])++ ;'?\n", errout.str());
ASSERT_EQUALS("[test.cpp:2]: (warning) Ineffective statement similar to '*A++;'. Did you intend to write '(*A)++;'?\n", errout.str());
check("void f(Foo f) {\n"
" *f.a(1, 5).v[x + y]++;\n"
"}");
ASSERT_EQUALS("[test.cpp:2]: (warning) Ineffective statement: '* f . a ( 1 , 5 ) . v [ x + y ] ++ ;'. Did you intend to write '(* f . a ( 1 , 5 ) . v [ x + y ])++ ;'?\n", errout.str());
ASSERT_EQUALS("[test.cpp:2]: (warning) Ineffective statement similar to '*A++;'. Did you intend to write '(*A)++;'?\n", errout.str());
check("char* f(char* c) {\n"
" (*c)++;\n"
@ -4084,13 +4084,13 @@ private:
" ***c++;\n"
" return c;\n"
"}");
ASSERT_EQUALS("[test.cpp:2]: (warning) Ineffective statement: '* * * c ++ ;'. Did you intend to write '(* * * c)++ ;'?\n", errout.str());
ASSERT_EQUALS("[test.cpp:2]: (warning) Ineffective statement similar to '*A++;'. Did you intend to write '(*A)++;'?\n", errout.str());
check("char** f(char*** c) {\n"
" **c[5]--;\n"
" return **c;\n"
"}");
ASSERT_EQUALS("[test.cpp:2]: (warning) Ineffective statement: '* * c [ 5 ] -- ;'. Did you intend to write '(* * c [ 5 ])-- ;'?\n", errout.str());
ASSERT_EQUALS("[test.cpp:2]: (warning) Ineffective statement similar to '*A++;'. Did you intend to write '(*A)++;'?\n", errout.str());
check("char*** f(char*** c) {\n"
" (***c)++;\n"