This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Tentative patch to catch a[n]=b[n++]...
- To: egcs at cygnus dot com
- Subject: Tentative patch to catch a[n]=b[n++]...
- From: Michael Meeks <michael at imaginator dot com>
- Date: Thu, 19 Mar 1998 15:35:47 +0000 (GMT)
- Reply-To: Michael Meeks <michael at imaginator dot com>
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 :-) eg.
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 [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, as I know there are always
cases that are not possible to trap eg.
int a ;
int *b = &a, *c = &a ;
*b = *c++ ;
etc.
The other thing is that my internet connection disappears on 21st
until the summer term. I suppose that means I shouldn't post a patch as I
can't support it until then ?
Thanks for your advice,
Michael Meeks.
--
michael@imaginator.com <><, Pseudo Engineer, itinerant idiot