As our code already compiles with GCC, I think perhaps the fastest way might be:
- build a GCC
- create a custom modification of GCC so that it prints warning (or error) whenever pointer subtraction is detected
- build the project and gather all warnings about pointer subtraction
Here is the outline of changes which need to be done to GCC for this:
Add your warnings into:
- c-typeck.c (
pointer_diff
function)
- cp/typeck.c (
pointer_diff
function).
Besides of directly detecting pointer subtraction, another thing to do can be to detect cases where you first convert pointers to integral types and then subtract them. This may be more difficult depending on how is your code structured, in out case regexp search for (.*intptr_t).-.-(.*intptr_t) has worked quite well.