This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Why no warning? (was: Re: Tree generation bug or a feature?)



Yuri Pudgorodsky wrote:
> x = 2;  y = ++x * ++x;
> x = 2;  y = (x+=1) * (x+=1);

This is in every C FAQ, and yet it is still a frequently asked question
here and other places.  I see it asked in news groups and have had people
say "hey, look at this compiler bug!" to me at the University.

Would it be difficult to add a warning for use of a variable more than once
in an expression which has a side effect on the variable?  Does some flag
exist to do this now?... a grep in the info directory only turned up one
place where it said the order that side effects occur isn't defined.  It
_didn't_ mention that the result might not correspond with any ordering or
that the compiler might make pigs fly across the screen...

Even if it were difficult to print a warning for these cases, it might be
worth while to do so because people are just very confused when the
compiler doesn't do what they expect.

It might even be good to turn on by default since this is not only
undefined behavior, but results from actual compilers vary.

-Ross

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]