Movatterモバイル変換


[0]ホーム

URL:


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


1054. Lvalue-to-rvalue conversions in expression statements

Section:8.3  [stmt.expr]    Status:C++11    Submitter:Hans Boehm    Date:2010-03-16

[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):

  1. Add a new paragraph after Clause 7 [expr] paragraph10:

  2. 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:

  3. Change 7.6.1.9 [expr.static.cast] paragraph 6 as follows:

  4. 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.
  5. Change 7.6.20 [expr.comma] paragraph 1 as follows:

  6. ...A pair of expressions separated by a comma is evaluatedleft-to-right;and the value of the 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...
  7. Change 8.3 [stmt.expr] paragraph 1 as follows:

  8. ...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...



[8]ページ先頭

©2009-2026 Movatter.jp