Skip to content

Commit f2b1359

Browse files
committed
fix
1 parent 3c3902c commit f2b1359

2 files changed

Lines changed: 4 additions & 4 deletions

File tree

lib/checkassert.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ void CheckAssertImpl::assertWithSideEffects()
8383
if (!scope) {
8484
// guess that const method doesn't have side effects
8585
if (f->nestedIn->isClassOrStruct() && !f->isConst() && !f->isStatic())
86-
sideEffectInAssertError(tmp, f->name()); // Non-const member function called, assume it has side effects
86+
sideEffectInAssertError(tmp, f->name(), " If there are no side effects, consider declaring the method const."); // Non-const member function called, assume it has side effects
8787
continue;
8888
}
8989

@@ -117,12 +117,12 @@ void CheckAssertImpl::assertWithSideEffects()
117117
//---------------------------------------------------------------------------
118118

119119

120-
void CheckAssertImpl::sideEffectInAssertError(const Token *tok, const std::string& functionName)
120+
void CheckAssertImpl::sideEffectInAssertError(const Token *tok, const std::string& functionName, const std::string &extra)
121121
{
122122
reportError(tok, Severity::warning,
123123
"assertWithSideEffect",
124124
"$symbol:" + functionName + "\n"
125-
"Assert statement calls a function which may have desired side effects: '$symbol'.\n"
125+
"Assert statement calls a function which may have desired side effects: '$symbol'." + extra + "\n"
126126
"Non-pure function: '$symbol' is called inside assert statement. "
127127
"Assert statements are removed from release builds so the code inside "
128128
"assert statement is not executed. If the code is needed also in release "

lib/checkassert.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ class CPPCHECKLIB CheckAssertImpl : public CheckImpl {
6565
void checkVariableAssignment(const Token* assignTok, const Scope *assertionScope);
6666
static bool inSameScope(const Token* returnTok, const Token* assignTok);
6767

68-
void sideEffectInAssertError(const Token *tok, const std::string& functionName);
68+
void sideEffectInAssertError(const Token *tok, const std::string& functionName, const std::string &extra = "");
6969
void assignmentInAssertError(const Token *tok, const std::string &varname);
7070
};
7171
/// @}

0 commit comments

Comments
 (0)