Hello!
I am working on a new checker; function parameter can be const.
I plan to warn when:
* a function parameter is not const
* the function parameter is a pointer
* it is dereferenced in the function (otherwise there will be -Wunused-parameter warnings)
* the pointer address is not taken
* the data is not written
Example code:
int x;
void warn(int *p) { x = *p; } // <- Warning
void dontwarn(int *p) { *p = 0; } // <- No warning, data is written
My checker works a bit like the -Wunused-parameter warning. I add a flag to Decl that says if there is non-const usage.
I attach a proof-of-concept patch. It does not work well yet but shows how I intend to implement this.
Best regards,
Daniel Marjamäki
..................................................................................................................
Daniel Marjamäki Senior Engineer
Evidente ES East AB Warfvinges väg 34 SE-112 51 Stockholm Sweden
Mobile: +46 (0)709 12 42 62
E-mail: Daniel.Marjamaki@evidente.se
www.evidente.se
150805-constpar.diff (4.48 KB)