Restrictions on use of non-static data members
_N4567_.5.1.1 [expr.prim.general]
Jason Merrill

Created on 2009-04-01.00:00:00 last changed 143 months ago


Date: 2009-10-15.00:00:00

[Voted into WP at October, 2009 meeting.]

Date: 2009-07-15.00:00:00

Proposed resolution (July, 2009):

Change _N4567_.5.1.1 [expr.prim.general] paragraph 10 as follows:

  • ...

  • if that id-expression denotes a non-static data member and it is the sole constituent of appears in an unevaluated operand, except for optional enclosing parentheses. [Example:

      struct S {
        int m;
      int i = sizeof(S::m);        // OK
      int j = sizeof(S::m + 42);   // error: reference to non-static member in subexpression OK

    end example]

Date: 2017-02-06.00:00:00

The resolution of issue 613, as reflected in the sixth bullet of _N4567_.5.1.1 [expr.prim.general] paragraph 10, allows an id-expression designating a non-static data member to be used

  • if... it is the sole constituent of an unevaluated operand, except for optional enclosing parentheses.

The requirement that the id-expression be the “sole constituent” of the unevaluated operand seems unnecessarily strict, forbidding such plausible use cases as

    struct S {
        int ar[42];
    int i = sizeof(S::ar[0]);

or the use of the member as a function argument in template metaprogramming. The more general version of the restriction seems not to be very difficult to implement and may actually represent a simplification in some implementations.

Date User Action Args
2010-03-29 00:00:00adminsetstatus: dr -> cd2
2009-11-08 00:00:00adminsetmessages: + msg2432
2009-11-08 00:00:00adminsetstatus: ready -> dr
2009-08-03 00:00:00adminsetmessages: + msg2144
2009-08-03 00:00:00adminsetstatus: open -> ready
2009-04-01 00:00:00admincreate