Title
Missing definition of "temporary expression"
Status
drafting
Section
6.7.7 [class.temporary]
Submitter
Brian Bi

Created on 2022-12-16.00:00:00 last changed 9 months ago

Messages

Date: 2024-03-21.12:19:10

CWG 2024-03-21

The phrasing "If a reference is bound to an object O that is the result of a temporary expression, ..." can be interpreted to refer to any temporary expression, even one entirely unrelated to the initializer of the reference.

Date: 2023-12-02.15:54:05

Proposed resolution (approved by CWG 2023-11-10):

  1. Change in 6.7.7 [class.temporary] paragraph 6 as follows:

    The third context is when a reference binds to a temporary object. [ Footnote: ... ] The temporary object to which the reference is bound or the temporary object that is the complete object of a subobject to which the reference is bound persists for the lifetime of the reference if the glvalue to which the reference is bound was A temporary expression is a glvalue obtained through one of the following:
    • a temporary materialization conversion (7.3.5 [conv.rval]),
    • ( expression ), where expression is one of these expressions a temporary expression,
    • subscripting (7.6.1.2 [expr.sub]) of an array operand, where that operand is one of these expressions a temporary expression,
    • a class member access (7.6.1.5 [expr.ref]) using the . operator where the left operand is one of these expressions a temporary expression and the right operand designates a non-static data member of non-reference type,
    • a pointer-to-member operation (7.6.4 [expr.mptr.oper]) using the .* operator where the left operand is one of these expressions a temporary expression and the right operand is a pointer to data member of non-reference type,
    • a converting, without a user-defined conversion, a glvalue operand that is one of these expressions a temporary expression to a glvalue that refers to the object designated by the operand, or to its complete object or a subobject thereof,
    • a conditional expression (7.6.16 [expr.cond]) that is a glvalue where the second or third operand is one of these expressions a temporary expression, or
    • a comma expression (7.6.20 [expr.comma]) that is a glvalue where the right operand is one of these expressions a temporary expression.
    If a reference is bound to an object O that is the result of a temporary expression, the complete object of O persists for the lifetime of the reference.
  2. Change in 11.9.3 [class.base.init] paragraph 8 as follows:

    A temporary expression bound to Binding a reference member to an object that is the result of a temporary expression in a mem-initializer is ill-formed.
  3. Change in 11.9.3 [class.base.init] paragraph 11 as follows:

    A temporary expression bound to Binding a reference member to an object that is the result of a temporary expression from a default member initializer is ill-formed.
Date: 2023-12-02.15:54:05

The term "temporary expression" is used in 11.9.3 [class.base.init] paragraph 8 and 11.9.3 [class.base.init] paragraph 11, but is never defined.

History
Date User Action Args
2024-03-21 12:19:10adminsetmessages: + msg7652
2024-03-21 12:19:10adminsetstatus: ready -> drafting
2024-03-20 14:10:31adminsetstatus: tentatively ready -> ready
2023-12-02 15:54:05adminsetmessages: + msg7539
2023-12-02 15:54:05adminsetstatus: open -> tentatively ready
2022-12-16 00:00:00admincreate