Oops, meant to send this to the mailing list instead of to Reid
privately. (Why cc the mailing list instead of just sending to the
mailing list?)
In article <CACs=tyJ6zaHeiS0eNhBkdcZE--JY4k7yH9_P1yFbGqod6uymMw at
mail.gmail.com>,
Reid Kleckner <rnk at google.com> writes:
> Looks like a bug. This can probably be simplified with C++11.
>
> On Fri, Apr 4, 2014 at 10:39 AM, Robison, Arch <arch.robison at
intel.com>wrote:
>
> > for (; I != E; I = ++I) {
> > ...
> > }
> >
> > Is there a reason for writing "I = ++I" instead of
"++I" ?
I don't see how it's a bug because functionality isn't impacted by
this. It's simply a redundant assignment.
I also don't see what C++11 has to do with this.
i = i;
has always been legal since the very first implementation of C and has
always been a pointless expression.
Had the code been:
i = i++;
then we would have had a real problem since i++ returns the old value
of i before it was incremented and the loop would be infinite.
--
"The Direct3D Graphics Pipeline" free book
<http://tinyurl.com/d3d-pipeline>
The Computer Graphics Museum <http://ComputerGraphicsMuseum.org>
The Terminals Wiki <http://terminals.classiccmp.org>
Legalize Adulthood! (my blog) <http://LegalizeAdulthood.wordpress.com>
Joerg Sonnenberger
2014-Apr-07 19:09 UTC
[LLVMdev] Why "I = ++I" instead of "++I" in COFFDump.cpp ?
On Mon, Apr 07, 2014 at 08:38:58AM -0600, Richard wrote:> Oops, meant to send this to the mailing list instead of to Reid > privately. (Why cc the mailing list instead of just sending to the > mailing list?) > > In article <CACs=tyJ6zaHeiS0eNhBkdcZE--JY4k7yH9_P1yFbGqod6uymMw at mail.gmail.com>, > Reid Kleckner <rnk at google.com> writes: > > > Looks like a bug. This can probably be simplified with C++11. > > > > On Fri, Apr 4, 2014 at 10:39 AM, Robison, Arch <arch.robison at intel.com>wrote: > > > > > for (; I != E; I = ++I) { > > > ... > > > } > > > > > > Is there a reason for writing "I = ++I" instead of "++I" ? > > I don't see how it's a bug because functionality isn't impacted by > this. It's simply a redundant assignment.It is a bug as it violates the sequence point rule. One memory location shall not be modified twice. Joerg
In article <20140407190957.GA11923 at britannica.bec.de>,
Joerg Sonnenberger <joerg at britannica.bec.de> writes:
> On Mon, Apr 07, 2014 at 08:38:58AM -0600, Richard wrote:
> > In article <CACs=tyJ6zaHeiS0eNhBkdcZE--JY4k7yH9_P1yFbGqod6uymMw at
mail.gmail.com>,
> > Reid Kleckner <rnk at google.com> writes:
> >
> > > Looks like a bug. This can probably be simplified with C++11.
> > >
> > > On Fri, Apr 4, 2014 at 10:39 AM, Robison, Arch <arch.robison
at intel.com>wrote:
> > > > Is there a reason for writing "I = ++I" instead of
"++I" ?
> >
> > I don't see how it's a bug because functionality isn't
impacted by
> > this. It's simply a redundant assignment.
>
> It is a bug as it violates the sequence point rule. One memory location
> shall not be modified twice.
Hrm. Then it's really two bugs?
1) the code violates the sequence point rule.
2) gcc/clang/MSVC didn't complain when compiling this code
If you could point me to the appropriate section of the Nov. 2012 Draft
Standard where I could read about the sequence point rule, I would be very
appreciative as I would like to understand this better.
Thanks!
--
"The Direct3D Graphics Pipeline" free book
<http://tinyurl.com/d3d-pipeline>
The Computer Graphics Museum <http://ComputerGraphicsMuseum.org>
The Terminals Wiki <http://terminals.classiccmp.org>
Legalize Adulthood! (my blog) <http://LegalizeAdulthood.wordpress.com>
Richard Smith
2014-Apr-08 00:21 UTC
[LLVMdev] Why "I = ++I" instead of "++I" in COFFDump.cpp ?
On Mon, Apr 7, 2014 at 12:09 PM, Joerg Sonnenberger <joerg at britannica.bec.de> wrote:> On Mon, Apr 07, 2014 at 08:38:58AM -0600, Richard wrote: > > Oops, meant to send this to the mailing list instead of to Reid > > privately. (Why cc the mailing list instead of just sending to the > > mailing list?) > > > > In article <CACs> tyJ6zaHeiS0eNhBkdcZE--JY4k7yH9_P1yFbGqod6uymMw at mail.gmail.com>, > > Reid Kleckner <rnk at google.com> writes: > > > > > Looks like a bug. This can probably be simplified with C++11. > > > > > > On Fri, Apr 4, 2014 at 10:39 AM, Robison, Arch <arch.robison at intel.com > >wrote: > > > > > > > for (; I != E; I = ++I) { > > > > ... > > > > } > > > > > > > > Is there a reason for writing "I = ++I" instead of "++I" ? > > > > I don't see how it's a bug because functionality isn't impacted by > > this. It's simply a redundant assignment. > > It is a bug as it violates the sequence point rule. One memory location > shall not be modified twice.Not in C++11, and (probably) not in C11. The side-effect of pre-increment is sequenced before its value computation, and its value computation is sequenced before the assignment. (C++ doesn't have sequence points any more, and C only has them as a vestigial remnant of the pre-memory-model world.) -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20140407/09541b3f/attachment.html>