On Thu, Jan 24, 2013 at 10:06 AM, Robert Dewar <de...@adacore.com> wrote: > On 1/24/2013 10:02 AM, Jeffrey Walton wrote: > >> What I am not clear about is when an operation is deemed "undefined" >> or "implementation defined". > > > The compiler is free to assume that no arithmetic operation > on signed integers results in overflow. It is allowed to > take advantage of such assumptions in generating code (and > it does so). > > You have no right to assume *anything* about the semantics > of code that has an integer overflow (let alone make > asssumptions about the generated code). Well, I kind of agree with you. When taking arbitrary inputs, how does one know 'a priori'?
In this case, I claim we must perform the operation. Its the result that we can't use under some circumstances (namely, overflow or wrap). > This is truly undefined, not implementation defined, and > if your program has such an overflow, you cannot assume > ANYTHING about the generated code. Signed integers that suffer overflow are operating in "undefined" behavior territory. Does the C/C++ standard specify what to do in this case? Currently, I believe GCC removes the code rather than performing the operation or failing the compile. Unsigned integers that wrap/carry enjoy "implementation defined" behavior. The GCC maintainers are free to do what they want with "implementation defined." At the moment, GCC handles wrap/carry as expected - they perform the operation. Jeff