I have a function with a pointer as a parameter. The pointer is read, but the only write happens in a function call exclusive to a #if Feature. Similar to this minimal snippet.
`
void fun(myStruct *pStruct, int other, int parameters) {
... more code here
#if Feature
//pStruct only changed in this function
mutatesMyStruct(pStruct);
#endif
... more code here
}
void mutatesMyStruct(myStruct *pStruct){...}
`
I then use cmake to generate compile commands for both feature flags and merge the resulting json files and use it as the --project.
When I now generate a report with cppcheck I get the following style warning:
Parameter pStruct can be declared as pointer to const"
Is this the intended behaviour? And if yes is there a better way to do this or to circumvent this warning without supressing it?
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I have a function with a pointer as a parameter. The pointer is read, but the only write happens in a function call exclusive to a #if Feature. Similar to this minimal snippet.
`
void fun(myStruct *pStruct, int other, int parameters) {
... more code here
#if Feature
//pStruct only changed in this function
mutatesMyStruct(pStruct);
#endif
... more code here
}
void mutatesMyStruct(myStruct *pStruct){...}
`
I then use cmake to generate compile commands for both feature flags and merge the resulting json files and use it as the --project.
When I now generate a report with cppcheck I get the following style warning:
Parameter pStruct can be declared as pointer to const"
Is this the intended behaviour? And if yes is there a better way to do this or to circumvent this warning without supressing it?
It is not intended in my opinion.. I have created this ticket:
https://trac.cppcheck.net/ticket/12265