assignment in assert: modified the error message to better explain the reason why the warning is given.

This commit is contained in:
Daniel Marjamäki 2010-10-11 17:59:08 +02:00
parent a6e915f0cd
commit 3dfcbfc0e0
2 changed files with 11 additions and 8 deletions

View File

@ -235,6 +235,9 @@ void CheckOther::checkSelfAssignment()
//---------------------------------------------------------------------------
void CheckOther::checkAssignmentInAssert()
{
if (!_settings->_checkCodingStyle)
return;
const char assertPattern[] = "assert ( %any%";
const Token *tok = Token::findmatch(_tokenizer->tokens(), assertPattern);
const Token *endTok = tok ? tok->next()->link() : NULL;
@ -4185,8 +4188,8 @@ void CheckOther::selfAssignmentError(const Token *tok, const std::string &varnam
void CheckOther::assignmentInAssertError(const Token *tok, const std::string &varname)
{
reportError(tok, Severity::error,
"assignmentInAssert", "Assert statement modifies '" + varname + "' instead of just testing it");
reportError(tok, Severity::style,
"assignmentInAssert", "Assert statement modifies '" + varname + "'. If the modification is needed in release builds there is a bug.");
}
void CheckOther::misusedScopeObjectError(const Token *tok, const std::string& varname)

View File

@ -3181,7 +3181,7 @@ private:
" return a;\n"
"}\n"
);
ASSERT_EQUALS("[test.cpp:3]: (error) Assert statement modifies 'a' instead of just testing it\n", errout.str());
ASSERT_EQUALS("[test.cpp:3]: (style) Assert statement modifies 'a'. If the modification is needed in release builds there is a bug.\n", errout.str());
check("void f() {\n"
" int a = 0;\n"
@ -3198,7 +3198,7 @@ private:
" return a;\n"
"}\n"
);
ASSERT_EQUALS("[test.cpp:4]: (error) Assert statement modifies 'b' instead of just testing it\n", errout.str());
ASSERT_EQUALS("[test.cpp:4]: (style) Assert statement modifies 'b'. If the modification is needed in release builds there is a bug.\n", errout.str());
check("void f() {\n"
" int a = 0;\n"
@ -3206,7 +3206,7 @@ private:
" return a;\n"
"}\n"
);
ASSERT_EQUALS("[test.cpp:3]: (error) Assert statement modifies 'a' instead of just testing it\n", errout.str());
ASSERT_EQUALS("[test.cpp:3]: (style) Assert statement modifies 'a'. If the modification is needed in release builds there is a bug.\n", errout.str());
check("void f() {\n"
" int a = 0;\n"
@ -3214,7 +3214,7 @@ private:
" return a;\n"
"}\n"
);
ASSERT_EQUALS("[test.cpp:3]: (error) Assert statement modifies 'a' instead of just testing it\n", errout.str());
ASSERT_EQUALS("[test.cpp:3]: (style) Assert statement modifies 'a'. If the modification is needed in release builds there is a bug.\n", errout.str());
check("void f() {\n"
" int a = 0;\n"
@ -3222,7 +3222,7 @@ private:
" return a;\n"
"}\n"
);
ASSERT_EQUALS("[test.cpp:3]: (error) Assert statement modifies 'a' instead of just testing it\n", errout.str());
ASSERT_EQUALS("[test.cpp:3]: (style) Assert statement modifies 'a'. If the modification is needed in release builds there is a bug.\n", errout.str());
check("void f() {\n"
" int a = 0;\n"
@ -3230,7 +3230,7 @@ private:
" return a;\n"
"}\n"
);
ASSERT_EQUALS("[test.cpp:3]: (error) Assert statement modifies 'a' instead of just testing it\n", errout.str());
ASSERT_EQUALS("[test.cpp:3]: (style) Assert statement modifies 'a'. If the modification is needed in release builds there is a bug.\n", errout.str());
}
};