Date
2022-11-20.07:54:16
Message id
6009

Content

P0145 caused this situation:

  extern "C" void abort();

  struct A
  {
    int i;
    int data[10000];
  } a;

  A& aref() { a.i++; return a; }
  int main()
  {
    aref() = a;
    if (a.i != 0)
      abort();
  }

Is a.i now required to be 0?

A related example is this:

  int b;
  int& bref() { ++b; return b; }
  int main() {
    bref() = b;
    if (b != 0)
      abort();
  }

Here, b is required to be 0 after the assignment, because the value computation of the RHS of the assignment is sequenced before any side-effects on the LHS. The difference in guaranteed behavior between class and non-class types is disturbing.