diff --git a/lib/checkother.cpp b/lib/checkother.cpp index ef85d1469..346270f33 100644 --- a/lib/checkother.cpp +++ b/lib/checkother.cpp @@ -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) diff --git a/test/testother.cpp b/test/testother.cpp index 5451f18ac..931ddc247 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -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()); } };