Title
Constant expressions involving the address of an automatic variable
Status
cd1
Section
7.7 [expr.const]
Submitter
Jens Maurer

Created on 2008-03-13.00:00:00 last changed 162 months ago

Messages

Date: 2008-09-15.00:00:00

[Voted into the WP at the September, 2008 meeting (resolution in paper N2757).]

Date: 2008-06-15.00:00:00

Proposed resolution (June, 2008):

  1. Change 6.9.3.2 [basic.start.static] paragraph 1 as follows:

  2. Objects with static storage duration (6.7.5.2 [basic.stc.static]) or thread storage duration (3.7.2) shall be zero-initialized (9.4 [dcl.init]) before any other initialization takes place. A reference with static or thread storage duration and an object of trivial or literal type with static or thread storage duration can be initialized with a constant expression (7.7 [expr.const]); this is called constant initialization. Constant initialization is performed:
    • if an object of trivial or literal type with static or thread storage duration is initialized with a constant expression (7.7 [expr.const]), or

    • if a reference with static or thread storage duration is initialized with a constant expression that is not an lvalue designating an object with thread or automatic storage duration.

    Together, zero-initialization and constant initialization...
  3. Add the following in 7.7 [expr.const] paragraph 2:

    • an lvalue-to-rvalue conversion (4.1) unless it is applied to...

    • an array-to-pointer conversion (7.3.3 [conv.array]) that is applied to an lvalue that designates an object with thread or automatic storage duration

    • a unary operator & (7.6.2.2 [expr.unary.op]) that is applied to an lvalue that designates an object with thread or automatic storage duration

    • an id-expression that refers to a variable or data member of reference type;

    • ...

(Note: the change to 6.9.3.2 [basic.start.static] paragraph 1 needs to be reconciled with the conflicting change in issue 688.)

Date: 2008-03-13.00:00:00

The expressions that are excluded from being constant expressions in 7.7 [expr.const] paragraph 2 does not address an example like the following:

    void f() {
       int a;
       constexpr int* p = &a;    // should be ill-formed, currently isn't
    }

Suggested resolution:

Add the following bullet to the list in 7.7 [expr.const] paragraph 2:

  • an id-expression that refers to a variable with automatic storage duration unless a permitted lvalue-to-rvalue conversion is applied (see above)

History
Date User Action Args
2008-10-05 00:00:00adminsetmessages: + msg1816
2008-10-05 00:00:00adminsetstatus: review -> cd1
2008-06-29 00:00:00adminsetmessages: + msg1693
2008-06-29 00:00:00adminsetstatus: open -> review
2008-03-13 00:00:00admincreate