Search code examples
c++cppcheck

How to use cppcheck-suppress command to elimnate the error about "a parameter should be passed by reference"


In function "writeFile" below it has the following signature:

writeFile(std::string fileId, std::string otherVariable){} 

when I run it, an error: Function parameter 'aFileId' should be passed by const reference. [passedByValue] is recieved. However I don't want to pass it by const reference because the function is going to be binary incompatiable with other files. I wanted to do a "cppcheck suppress" to make it igone this. I tried the following

// cppcheck-suppress aFileId
writeFile(std::string aFileId, std::string otherVariable){} 

but it does not really work and I still get the same error.

To clarify more, I tried this as well...

writeFile(std::string aFileId,  // cppcheck-suppress aFileId
     std::string otherVariable) 
    {
       // stuff
    } 

Solution

  • You have to activate inline suppressions in general when calling cppcheck. Add the command line option --inline-suppr.