Movatterモバイル変換


[0]ホーム

URL:


Issue 1672 - WG21 CWG Issues
Title
Layout compatibility with multiple empty bases
Status
cd4
Section
11.4 [class.mem]
Submitter
Richard Smith

Created on2013-04-27.00:00:00 last changed109 months ago

Messages

msg5391 (view)
Date: 2014-11-15.00:00:00

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

msg5139 (view)
Date: 2014-10-15.00:00:00

Proposed resolution (October, 2014):

Change Clause 11 [class] paragraph 7 as indicated and add thefollowing as a new paragraph:

AclassS is astandard-layoutclassis a class thatif it:

  • ...

  • has nobase classes of the same type as thefirst non-static data memberelement of thesetM(S) of types (defined below) asa base class.109

M(X) is defined as follows:

  • IfX is a non-union class type, the setM(X) is empty ifX has no (possibly inherited(11.7 [class.derived])) non-static data members;otherwise, it consists of the type of the first non-staticdata member ofX (where said member may be an anonymousunion),X0, and the elements ofM(X0).

  • IfX is a union type, the setM(X),where eachUi is the type of theithnon-static data member ofX, is the union of allM(Ui) and the set containing allUi.

  • IfX is a non-class type, the setM(X) is empty.

[Note:M(X) is the set of the types of allnon-base-class subobjects that are guaranteed in astandard-layout class to be at a zero offset inX.—end note]

(See also the related changes in the resolution forissue 1813.)

msg4520 (view)
Date: 2022-02-18.07:47:23

The layout compatibility rules of 11.4 [class.mem] paragraph16 are phrased only in terms of non-static data members, ignoring theexistence of base classes:

Two standard-layout struct (Clause 11 [class]) types arelayout-compatible if they have the same number of non-static data membersand corresponding non-static data members (in declaration order) havelayout-compatible types (6.9 [basic.types]).

However, this means that in an example like

  struct empty {};  struct A { char a; };  struct also_empty : empty {};  struct C : empty, also_empty { char c; };  union U {    struct X { A a1, a2; } x;    struct Y { C c1, c2; } y;  } u;

u.x.a2.a andu.y.c2.c must have the same address,even thoughsizeof(A) would typically be 1 andsizeof(B) would need to be at least 2 to give theempty subobjects different addresses.

History
DateUserActionArgs
2017-02-06 00:00:00adminsetstatus: drwp -> cd4
2015-05-25 00:00:00adminsetstatus: dr -> drwp
2015-04-13 00:00:00adminsetmessages: +msg5391
2014-11-24 00:00:00adminsetstatus: tentatively ready -> dr
2014-10-13 00:00:00adminsetmessages: +msg5139
2014-10-13 00:00:00adminsetstatus: drafting -> tentatively ready
2013-10-14 00:00:00adminsetstatus: open -> drafting
2013-04-27 00:00:00admincreate

[8]ページ先頭

©2009-2026 Movatter.jp