Added check: passing constant function parameter by value instead of by reference/pointer

This commit is contained in:
Daniel Marjamäki 2008-05-03 07:20:25 +00:00
parent 15fe28272c
commit cae2e190da
3 changed files with 23 additions and 1 deletions

View File

@ -693,6 +693,23 @@ static void CheckVariableScope_LookupVar( const TOKEN *tok1, const char varname[
ReportErr( errmsg.str() );
}
//---------------------------------------------------------------------------
//---------------------------------------------------------------------------
// Check for constant function parameters
//---------------------------------------------------------------------------
void CheckConstantFunctionParameter()
{
for (const TOKEN *tok = tokens; tok; tok = tok->next)
{
if ( Match(tok,"[,(] const std :: string %var% [,)]") )
{
std::ostringstream errmsg;
errmsg << FileLine(tok) << " looks like a constant function parameter that is passed by value";
ReportErr( errmsg.str() );
}
}
}

View File

@ -40,6 +40,9 @@ void CheckUnsignedDivision();
// Check scope of variables
void CheckVariableScope();
// Check for constant function parameter
void CheckConstantFunctionParameter();
//---------------------------------------------------------------------------
#endif

View File

@ -298,8 +298,10 @@ static void CppCheck(const char FileName[], unsigned int FileId)
// Variable scope (check if the scope could be limited)
CheckVariableScope();
}
// Check if a constant function parameter is passed by value
CheckConstantFunctionParameter();
}
// Clean up tokens..
DeallocateTokens();