Added check: passing constant function parameter by value instead of by reference/pointer
This commit is contained in:
parent
15fe28272c
commit
cae2e190da
|
@ -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() );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
|
@ -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
|
||||||
|
|
||||||
|
|
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)
|
// 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();
|
||||||
|
|
Loading…
Reference in New Issue