<html><head></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><div><div>On Oct 13, 2011, at 5:54 AM, Sebastian Redl wrote:</div><blockquote type="cite">
<meta content="text/html; charset=ISO-8859-1" http-equiv="Content-Type">
<div bgcolor="#FFFFFF" text="#000000">
On 13.10.2011 14:24, Sebastian Redl wrote:
<blockquote cite="mid:4E96D86B.5010806@getdesigned.at" type="cite">
<meta content="text/html; charset=ISO-8859-1" http-equiv="Content-Type">
On 13.10.2011 13:43, Abramo Bagnara wrote:
<blockquote cite="mid:4E96CECF.1000704@gmail.com" type="cite">
<pre wrap="">I want to put this gcc bug report to clang developer attention.
<a moz-do-not-send="true" class="moz-txt-link-freetext" href="http://gcc.gnu.org/bugzilla/show_bug.cgi?id=50364">http://gcc.gnu.org/bugzilla/show_bug.cgi?id=50364</a>
The gcc developers believe that according to the standard
volatile int v;
x = v = 3;
does not imply necessarily a read from v.
clang instead add a lvalue-to-rvalue implicit cast outside v = 3
assignment (and there is general consensus that lvalue-to-rvalue *is*
the marker for memory read access).
</pre>
</blockquote>
C++11 5.17 [expr.ass]p1 says:<br>
"The assignment operator (=) and the compound assignment operators
all group right-to-left. All require a modiļ¬able lvalue as their
left operand and <b>return an lvalue referring to the left
operand</b>."<br>
So the result of (v = 3) is an lvalue referring to v, just as the
expression (v) alone. Therefore the code is equivalent to the two
separate statements:<br>
v = 3;<br>
x = v;<br>
<br>
Clang is right, GCC is wrong.<br>
</blockquote>
To clarify: this is only C++. In C, the situation is different. C99
6.5.16p3 says:<br>
"An assignment expression has the value of the left operand after
the assignment, but is not an lvalue."<br>
<br>
So in C, GCC is right, and Clang is wrong.<br></div></blockquote><div><br></div>Or rather, in C, Clang would be wrong if it emitted a volatile read here, which it does not. Clang implements different semantics in the two languages.</div><div><br></div><div><blockquote type="cite"><div bgcolor="#FFFFFF" text="#000000">It could be considered a defect of one of the two languages that
they differ in such a subtle detail.<br></div></blockquote><div><br></div>Indeed, and the C++ committee has actually made some attempts to change this in C++11, but we haven't implemented those changes yet, and we're likely to only implement them in C++11 mode (i.e., treat C++11 as explicitly changing the semantics, rather than treating it as a true fix).</div><div><br></div><div>John.</div></body></html>