Added check: passing constant function parameter by value instead of by reference/pointer
This commit is contained in:
parent
15fe28272c
commit
cae2e190da
|
@ -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() );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -40,6 +40,9 @@ void CheckUnsignedDivision();
|
|||
// Check scope of variables
|
||||
void CheckVariableScope();
|
||||
|
||||
// Check for constant function parameter
|
||||
void CheckConstantFunctionParameter();
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
#endif
|
||||
|
||||
|
|
4
main.cpp
4
main.cpp
|
@ -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();
|
||||
|
|
Loading…
Reference in New Issue