after reading about sequence points, I learned that i = ++i
is undefined.
So how about this code:
int i;
int *p = &i;
int *q = &i;
Yes, this is undefined behavior -- you have two modifications of an object without a sequence point between them. Unfortunately, checking for this automatically is very hard -- the best I can think of is adding assert(p != q)
right before this, which will at least give a clean runtime fault rather than something worse. Checking this at compile time is undecidable in the general case.