Created on2013-04-27.00:00:00 last changed109 months ago
[Moved to DR at the November, 2014 meeting.]
Proposed resolution (October, 2014):
Change Clause 11 [class] paragraph 7 as indicated and add thefollowing as a new paragraph:
AclassS is astandard-layoutclass
is a class thatif it:
...
has no
base classes of the same type as thefirst non-static data memberelement of thesetM(S) of types (defined below) asa base class.109M(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.)
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 | |||
|---|---|---|---|
| Date | User | Action | Args |
| 2017-02-06 00:00:00 | admin | set | status: drwp -> cd4 |
| 2015-05-25 00:00:00 | admin | set | status: dr -> drwp |
| 2015-04-13 00:00:00 | admin | set | messages: +msg5391 |
| 2014-11-24 00:00:00 | admin | set | status: tentatively ready -> dr |
| 2014-10-13 00:00:00 | admin | set | messages: +msg5139 |
| 2014-10-13 00:00:00 | admin | set | status: drafting -> tentatively ready |
| 2013-10-14 00:00:00 | admin | set | status: open -> drafting |
| 2013-04-27 00:00:00 | admin | create | |