Title
Aliasing this
Status
c++17
Section
11.4.5 [class.ctor]
Submitter
Richard Smith

Created on 2016-06-20.00:00:00 last changed 36 months ago

Messages

Date: 2016-11-15.00:00:00

[Moved to DR at the November, 2016 meeting.]

Date: 2016-06-15.00:00:00

Proposed resolution (June, 2016):

Change 11.4.5 [class.ctor] paragraph 12 as follows:

During the construction of a const an object, if the value of the object or any of its subobjects is accessed through a glvalue that is not obtained, directly or indirectly, from the constructor's this pointer, the value of the object or subobject thus obtained is unspecified. [Example:

  struct C;
  void no_opt(C*);

  struct C {
    int c;
    C() : c(0) { no_opt(this); }
  };

  const C cobj;

  void no_opt(C* cptr) {
    int i = cobj.c * 100; // value of cobj.c is unspecified
    cptr->c = 1;
    cout << cobj.c * 100  // value of cobj.c is unspecified
         << '\n';
  }

  extern struct D d;
  struct D {
    D(int a) : a(a), b(d.a) {}
    int a, b;
  };
  D d = D(1);             // value of d.b is unspecified

end example]

Date: 2016-06-20.00:00:00

The restrictions against aliasing this inside a constructor should apply to all objects, not just to const objects.

History
Date User Action Args
2018-02-27 00:00:00adminsetmessages: + msg6166
2018-02-27 00:00:00adminsetstatus: dr -> c++17
2017-02-06 00:00:00adminsetmessages: + msg6089
2016-06-20 00:00:00admincreate