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

@ -696,3 +696,20 @@ static void CheckVariableScope_LookupVar( const TOKEN *tok1, const char varname[
//---------------------------------------------------------------------------
// 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 // Check scope of variables
void CheckVariableScope(); void CheckVariableScope();
// Check for constant function parameter
void CheckConstantFunctionParameter();
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
#endif #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) // Variable scope (check if the scope could be limited)
CheckVariableScope(); CheckVariableScope();
}
// Check if a constant function parameter is passed by value
CheckConstantFunctionParameter();
}
// Clean up tokens.. // Clean up tokens..
DeallocateTokens(); DeallocateTokens();