Tentative patch to catch a[n]=b[n++]...
Michael Meeks
michael@imaginator.com
Sat Apr 25 17:40:00 GMT 1998
Hi,
I have written a patch for gcc-2.8.1 / egcs-1.0.2 that flags
warnings on the more simple cases of modifying a variable between sequence
points.
Since the code doesn't locate sequence points in a formal manner,
it will warn on some code that is correct but unadvisable :-) Here is a
list of results on my test code:
a = ++a + b ; /* Fail */
a = a-- + b ; /* Fail */
a = (a++ && 4) ; /* shouldn't Fail but does */
a[n]=b[n++] ; /* Fail */
a[--n]=b[n] ; /* Fail */
a[++n]=b[--n] ; /* Fail */
c[n][n]=c[n][n]++ ; /* should fail but doesn't */
c[n][p]=c[n][n++] ; /* Fail */ /* if lvalue [n][n] then fails twice */
*ptr++ = (int)ptr++ ; /* Fail */
ptr->a = ptr->a++ ; /* should fail but doesn't */
ptr->a = (int)(ptr++) ; /* Fail */
a = b = a++ ; /* Fail */
b = a = --b ; /* Fail */
a = 1 + (a=1) ; /* Fail */
a = (a=b) ; /* Fail */
a = (a=b) + 1 ; /* Fail */
These cases are just hacked from my regression test code, does
this look like something that is sufficiently useful to include ? What
worries me is wrongly flagging correct cases. There are always cases that
are not possible to trap eg.
int a ;
int *b = &a, *c = &a ;
*b = *c++ ;
etc.
As I haven't grasped the process of Changelog entries / posting
patches etc. can someone help ?
Thanks for your time,
Michael Meeks.
--
michael@imaginator.com <><, Pseudo Engineer, itinerant idiot
More information about the Gcc
mailing list