This is an unofficial snapshot of the ISO/IEC JTC1 SC22 WG21 Core Issues List revision 119a. See http://www.open-std.org/jtc1/sc22/wg21/ for the official list.
2025-12-20
[Voted into the WP at the March, 2011 meeting.]
C and C++ differ in the treatment of an expression statement, inparticular with regard to whether a volatile lvalue is fetched. Forexample,
volatile int x; void f() { x; // Fetches x in C, not in C++ }The reason C++ is different in this regard is principally due tothe fact that an assignment expression is an lvalue in C++ but notin C. If the lvalue-to-rvalue conversion were applied to expressionstatements, a statement like
x = 5;
would write to x and then immediately read it.
It is not clear that the current approach to dealing with thedifference in assignment expressions is the only or best approach;it might be possible to avoid the unwanted fetch on the result ofan assignment statement without giving up the fetch for a variableappearing by itself in an expression statement.
Proposed resolution (January, 2011):
Add a new paragraph after Clause 7 [expr] paragraph10:
In some contexts, an expression only appears for itsside-effects. Such an expression is called adiscarded-valueexpression. The expression is evaluated and its value isdiscarded. The array-to-pointer (7.3.3 [conv.array]) andfunction-to-pointer (7.3.4 [conv.func]) standard conversionsare not applied. The lvalue-to-rvalue conversion (7.3.2 [conv.lval]) is applied only if the expression is an lvalue ofvolatile-qualified type and it has one of the followingforms:
id-expression (_N4567_.5.1.1 [expr.prim.general]),
subscripting (7.6.1.2 [expr.sub]),
class member access (7.6.1.5 [expr.ref]),
indirection (7.6.2.2 [expr.unary.op]),
pointer-to-member operation (7.6.4 [expr.mptr.oper]),
conditional expression (7.6.16 [expr.cond]) where boththe second and the third operand are one of the above, or
comma expression (7.6.20 [expr.comma]) where the rightoperand is one of the above.
Change 7.6.1.9 [expr.static.cast] paragraph 6 as follows:
Any expression can be explicitly converted to typecvvoid, in which case it becomes a discarded-valueexpression (Clause 7 [expr]).The expressionvalue is discarded.[Note: however, if the value is in atemporary object (6.8.7 [class.temporary]), the destructor for thatobject is not executed until the usual time, and the value of theobject is preserved for the purpose of executing the destructor.—end note]The lvalue-to-rvalue (7.3.2 [conv.lval]), array-to-pointer (7.3.3 [conv.array]), andfunction-to-pointer (7.3.4 [conv.func]) standard conversionsare not applied to the expression.
Change 7.6.20 [expr.comma] paragraph 1 as follows:
...A pair of expressions separated by a comma is evaluatedleft-to-right;and the value ofthe leftexpression isdiscardeda discarded-value expression(Clause 7 [expr]).83Thelvalue-to-rvalue (7.3.2 [conv.lval]), array-to-pointer(7.3.3 [conv.array]), and function-to-pointer (7.3.4 [conv.func]) standard conversions are not applied to the leftexpression.Every value computation...
Change 8.3 [stmt.expr] paragraph 1 as follows:
...The expression isevaluated and its value is discardeda discarded-value expression (Clause 7 [expr]).The lvalue-to-rvalue (7.3.2 [conv.lval]),array-to-pointer (7.3.3 [conv.array]), and function-to-pointer(7.3.4 [conv.func]) standard conversions are not applied to theexpression.All side effects...