Movatterモバイル変換


[0]ホーム

URL:


This is an unofficial snapshot of the ISO/IEC JTC1 SC22 WG21 Core Issues List revision 119a. See http://www.open-std.org/jtc1/sc22/wg21/ for the official list.

2025-12-20


2271. Aliasingthis

Section:11.4.5  [class.ctor]    Status:C++17    Submitter:Richard Smith    Date:2016-06-20

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

The restrictions against aliasingthis inside a constructorshould apply to all objects, not just to const objects.

Proposed resolution (June, 2016):

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

During the construction ofaconstanobject, if the value of the object or any of its subobjects is accessedthrough a glvalue that is not obtained, directly or indirectly, from theconstructor'sthis pointer, the value of the object or subobjectthus 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 ofcobj.c is unspecified    cptr->c = 1;    cout << cobj.c * 100  // value ofcobj.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 ofd.b is unspecified

end example]




[8]ページ先頭

©2009-2026 Movatter.jp