This is an unofficial snapshot of the ISO/IEC JTC1 SC22 WG21 Core Issues List revision 108i. See http://www.open-std.org/jtc1/sc22/wg21/ for the official list.

2022-07-16


1694. Restriction on reference to temporary as a constant expression

Section: 7.7  [expr.const]     Status: CD4     Submitter: Richard Smith     Date: 2013-05-30

[Moved to DR at the November, 2014 meeting.]

We're missing a restriction on the value of a temporary which is bound to a static storage duration reference:

  void f(int n) {
    static constexpr int *&&r = &n;
  }

This is currently valid, because &n is a core constant expression, and it is a constant expression because the reference binds to a temporary (of type int*) that has static storage duration (because it's lifetime-extended by the reference binding).

The value of r is constant here (it's a constant reference to a temporary with a non-constant initializer), but I don't think we should accept this. Generally, I think a temporary which is lifetime-extended by a constexpr variable should also be treated as if it were declared to be a constexpr object.

Proposed resolution (September, 2013) [SUPERSEDED]:

Change 7.7 [expr.const] paragraph 4 as follows:

A constant expression is either a glvalue core constant expression whose value refers to an object with static storage duration or to a function entity that is a permitted result of a constant expression, or a prvalue core constant expression whose value is an object where, for that object and its subobjects:

An entity is a permitted result of a constant expression if it is an object with static storage duration that is either not a temporary or is a temporary whose value satisfies the above constraints, or it is a function.

Proposed resolution (February, 2014):

Change 7.7 [expr.const] paragraph 4 as follows:

A constant expression is either a glvalue core constant expression whose value refers to an object with static storage duration or to a function entity that is a permitted result of a constant expression (as defined below), or a prvalue core constant expression whose value is an object where, for that object and its subobjects:

An entity is a permitted result of a constant expression if it is an object with static storage duration that is either not a temporary object or is a temporary object whose value satisfies the above constraints, or it is a function.