Skip to content

Instantly share code, notes, and snippets.

@ecatmur
Last active August 29, 2015 14:01
Show Gist options
  • Save ecatmur/cf7bc1e0e79ee6fe408e to your computer and use it in GitHub Desktop.
Save ecatmur/cf7bc1e0e79ee6fe408e to your computer and use it in GitHub Desktop.
odr-use fixes for array subscripting/indirection

To 3.2p2, add:

  • if e is a subscript expression (5.2.1), where one operand is of type "array of N T" or "reference to array of N T" and the other operand is a constant expression of integral or enumeration type with value n, where 0 <= n < N, the set contains the potential results of the operand of array type.
  • if e is an indirection expression (5.3.1), the set contains the potential results of the operand.

Modify 3.2p3 thus:

A variable x whose name appears as a potentially-evaluated expression ex is odr-used by ex unless applying the lvalue-to-rvalue conversion (4.1) to x or, if x is of array type, an element of x yields a constant expression (5.19) that does not invoke any nontrivial 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 (4.1) is applied to e, or e is a discarded-value expression (Clause 5).

@MWid
Copy link

MWid commented May 14, 2014

To 3.2p2, add:

  • if e is a subscript expression (5.2.1), where one operand is of type "array of N T" or "reference to array of N T" and the other operand is a constant expression of integral or unscoped enumeration type with value n, where 0 <= n < N, the set contains the potential results of the operand of array type.

(the reference part is not needed since expressions cannot have reference type)

I think there is a problem with the modification in 3.2p3.

struct S { static const double a[2] = {0.0,1.0}; };
double d = S::a[0];

Here S::a[0] is not a constant expression, since the array is not declared constexpr.

I'm not sure, if we need to add indirection. What use cases do you have in mind?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment