Title
Unclear definition of odr-use for arrays
Status
cd5
Section
6.3 [basic.def.odr]
Submitter
Hubert Tong

Created on 2015-09-02.00:00:00 last changed 48 months ago

Messages

Date: 2019-01-15.00:00:00

Proposed resolution (January, 2019):

This issue is resolved by the resolution of issue 2083.

Date: 2019-02-15.00:00:00

[Accepted as a DR at the February, 2019 meeting.]

The current definition of odr-use of a variable is problematic when applied to an array:

A variable x whose name appears as a potentially-evaluated expression ex is odr-used by ex unless applying the lvalue-to-rvalue conversion (7.3.2 [conv.lval]) to x yields a constant expression (7.7 [expr.const]) that does not invoke any non-trivial functions and, if x is an object, ex is an element of the set of potential results of an expression e, where either the lvalue-to-rvalue conversion (7.3.2 [conv.lval]) is applied to e, or e is a discarded-value expression (Clause 7 [expr]).

Consider an example like

  struct S {
    constexpr static const int arr[3] = { 0, 1, 2 };
  };
  int i = S::arr[1];  // Should not require S::arr to be defined

Although the “set of potential results” test correctly handles the subscripting operation (since the resolution of issue 1926), it requires applying the lvalue-to-rvalue conversion to S::arr itself and not just to the result of the subscripting operation. Class objects exhibit a similar problem.

History
Date User Action Args
2020-12-15 00:00:00adminsetmessages: + msg6349
2020-12-15 00:00:00adminsetstatus: drafting -> cd5
2015-09-02 00:00:00admincreate