* Joshua Maurice, on 14.09.2010 00:42:
First, I should mention that that last sentence was incorrect, and I addressed
my error in a more-or-less immediate self-correction follow-up.
In this article you address precisely the two points where I had to correct myself.
Again, sorry for posting two incorrect statements (the rest stands).
I'm been looking for this for a while now. I've even reread this
entire thread, and I can't seem to locate exactly it, "Gabriel's DR".
<url:
http://www.open-
std.org/jtc1/sc22/wg21/docs/cwg_active.html#636>
Can anyone provide a link or a concise example demonstrating what
current standard behavior is, and a quick explanation of what the new
standard behavior should be?
Regarding the first, there's AFAIK no clear consensus.
And I think that's because the parties discussing it have vested interests,
because except for Gabriel's DR (an inconsistency) the standard is clear, and
g++ is violating the standard when used with default options. But then default
options are generally not enough to make any C++ compiler standard-compliant. So
I'd put this in that same box, that one needs to tell the compiler to not apply
optimizations such as assuming no RTTI (msvc), assuming no exceptions (msvc), or
assuming no static-type-incompatible aliasing (g++) -- in short, the compiler
needs to be customized for standard C++.
Regarding your second question, ditto. ;-)
So, the intent of 3.10 / 15 is to list when an object may or may not
be aliased. What other deeper reason could there be to list such a
thing besides allowed compiler optimizations?
To define the language -- which is what the standard is about.
It tells you, for example, that "to access the stored value" of an object with
dynamic type 'double' through an lvalue of type 'int', is Undefined Behavior.
That's great, yes?
A nice constraint that ensures that you don't try to interpret a bitpattern in a
way that it was never intended to be interpreted, or, for that matter, exceeding
the object bounds, or invoking a trap (ouch).
Knowing the *dynamic type* is the problem, though. An optimization that looks
only at the static referent type of a pointer, does not in all cases know the
dynamic referent type (as exemplified by pointing into a union). The problem
with g++'s optimization, its so called "strict aliasing" which isn't part of the
standard, is that it incorrectly assumes that it knows the dynamic referent type
by checking only the static referent type.
The programmer can know this.
The optimizer may be able to prove it in certain cases.
But g++'s optimizer incorrectly takes it as granted that the static referent
type tells the full story (which it doesn't).
Almost any rule in the standard allows some optimization of some kind, and so
does §3.10/15.
The problem is that the concrete optimization that we're discussing, g++'s
"strict aliasing" assumption, goes beyond what the standard allows for.
Note that there is a similar presumed exhaustive list of well-defined
reinterpret_cast conversions, in C++98 §5.2.10, and that list is even explicitly
stated to be exhaustive, and then broken by the rules of the same
about-POD-members section that breaks the aliasing rules wrt. union.
So we have two separate issues:
A) Broken optimizer in g++.
B) Inconsistencies introduced by the about-POD-members section §9.2; it breaks
both the exhaustive list of valid reinterpret_cast's, and aliasing rules.
And it seems to me that some folks have attempted to hide (A) under the carpet
by focusing on (B), using the uncertainty (FUD) created by the inconsistencies
to create the impression that g++'s rule is in the standard somewhere.
It isn't.
[snip]
"Please try to add some logical inferences."
Also, I find that your suggestion that I did not provide inferences to
be insulting and distracting. Simply because you disagree with my
premises does not render my argument invalid (using the technical
logic definition) - it does not relate to my inferences. From your
point of view of the facts, that merely renders it not sound, not
invalid.
I'm sorry, but I really missed the inferences.
I could not connect your premises to your conclusions (and still can't).
As you know ;-), I speak my mind. "Think straight, talk straight." However,
while I apologize for my wording, I also thank you for the compliment that you
take my arguments seriously even though you've stated that you think that I'm
the sole holder of the opinion that I've advocated (and no, I'm not insulted by
that -- sh*t happens, as they say
, and I trust everything's OK after ).
Cheers & hth.,
- Alf