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]

Re: Is this a gcc bug?


On 13-Jan-2001, Alexandre Oliva <aoliva@redhat.com> wrote:
> On Jan 12, 2001, Axel Kittenberger <Anshil@gmx.net> wrote:
> 
> > bug.i:8: unpredictable behaviour due to undefined evaluation sequence of
> > 'x'
> 
> It's the behavior that is undefined.  How about:
> 
> undefined behavior: expression may modify `x' multiple times

You also get the warning for cases like

	printf("%d %d\n", x++, x);

where cause of the undefined behaviour is not that `x' was modified
multiple times, but that `x' was both modified and read.  The warning
that you suggest would not be appropriate in these cases.

It might be good to give different warnings for these two different
kinds of problems, depending on whether they violate the first
sentence of C99 6.5 #2, or the second:

 | 	Between the previous and next sequence point an object
 | 	shall have its stored value modified at  most  once  by  the
 | 	evaluation  of  an expression.  Furthermore, the prior value
 | 	shall be read only to determine the value to be stored.70)

For those that violate the first sentence, your suggested warning sounds OK.
But for those that violate the second, something like

	warning: undefined behavior: expression modifies `x' and reads `x'

would be better.

-- 
Fergus Henderson <fjh@cs.mu.oz.au>  |  "I have always known that the pursuit
                                    |  of excellence is a lethal habit"
WWW: <http://www.cs.mu.oz.au/~fjh>  |     -- the last words of T. S. Garp.

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