Title
Clarifying discarded-value expressions
Status
cd3
Section
Clause [7] [expr]
Submitter
Lawrence Crowl

Created on 2011-08-30.00:00:00 last changed 34 months ago

Messages

Date: 2012-10-15.00:00:00

[Moved to DR at the October, 2012 meeting.]

Date: 2012-02-15.00:00:00

Additional note (February, 2012):

A problem was discovered that was not addressed by the proposed resolution that was reviewed at the February, 2012 meeting, so the issue has been moved back to "review" status with revised wording.

Date: 2012-02-15.00:00:00

Proposed resolution (February, 2012):

Change Clause 7 [expr] paragraph 10 as follows:

...The lvalue-to-rvalue conversion (7.3.2 [conv.lval]) is applied if and only if the expression is an lvalue of volatile-qualified type and it has is one of the following forms:

  • ( expression ), where expression is one of these expressions,

  • id-expression (_N4567_.5.1.1 [expr.prim.general]),

  • ...

  • conditional expression (7.6.16 [expr.cond]) where both the second and the third operands are one of the above these expressions, or

  • comma expression (7.6.20 [expr.comma]) where the right operand is one of the above these expressions.

[Note: Using an overloaded operator causes a function call; the above covers only operators with built-in meaning. If the lvalue is of class type, it must have a volatile copy constructor to initialize the temporary that is the result of the lvalue-to-rvalue conversion. —end note]

Date: 2022-02-18.07:47:23

Suggested resolution:

In some contexts, an expression only appears for its side effects. Such an expression is called a discarded-value expression. The expression is evaluated and its value is discarded. The array-to-pointer (7.3.3 [conv.array]) and function-to-pointer (7.3.4 [conv.func]) standard conversions are not applied. The lvalue-to-rvalue conversion (7.3.2 [conv.lval]) is applied if and only if the expression is an lvalue of volatile-qualified type and it has one of the following forms:

  • id-expression (_N4567_.5.1.1 [expr.prim.general]),

  • subscripting subscript operation (7.6.1.2 [expr.sub]),

  • class member access (7.6.1.5 [expr.ref]),

  • indirection operation (7.6.2.2 [expr.unary.op]),

  • pointer-to-member operation (7.6.4 [expr.mptr.oper]),

  • conditional expression operation (7.6.16 [expr.cond]) where both the second and the third operands are one of the above these forms, or

  • comma expression operation (7.6.20 [expr.comma]) where the right operand is one of the above these forms.

[Note: Expressions invoking user-defined operators are not the operations above. Discarded-value expressions apply to class types, which will be ill-formed if there is no volatile copy constructor with which to initialize the temporary. —end note]

Date: 2022-02-18.07:47:23

There are some points in the description discarded-value expressions that need clarification:

  • Does this require the lvalue-to-rvalue conversion in the listed cases or only prohibit it in all other cases (“only if” vs “if and only if”)?

  • Does this apply only to built-in operations or to overloaded operators?

  • Does this apply to non-POD types?

History
Date User Action Args
2022-02-18 07:47:23adminsetmessages: + msg6704
2014-03-03 00:00:00adminsetstatus: drwp -> cd3
2013-05-03 00:00:00adminsetstatus: dr -> drwp
2012-11-03 00:00:00adminsetmessages: + msg4126
2012-11-03 00:00:00adminsetstatus: ready -> dr
2012-02-27 00:00:00adminsetmessages: + msg3696
2012-02-27 00:00:00adminsetmessages: + msg3695
2012-02-27 00:00:00adminsetstatus: open -> ready
2011-08-30 00:00:00admincreate