diff --git a/CheckOther.cpp b/CheckOther.cpp index f51110599..3aa52ecaa 100644 --- a/CheckOther.cpp +++ b/CheckOther.cpp @@ -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() ); + } + } +} diff --git a/CheckOther.h b/CheckOther.h index c9bded78d..07e376bb2 100644 --- a/CheckOther.h +++ b/CheckOther.h @@ -40,6 +40,9 @@ void CheckUnsignedDivision(); // Check scope of variables void CheckVariableScope(); +// Check for constant function parameter +void CheckConstantFunctionParameter(); + //--------------------------------------------------------------------------- #endif diff --git a/main.cpp b/main.cpp index 75c5d2575..21524102b 100644 --- a/main.cpp +++ b/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();