This is an unofficial snapshot of the ISO/IEC JTC1 SC22 WG21 Core Issues List revision 119d. See http://www.open-std.org/jtc1/sc22/wg21/ for the official list.
2026-03-14
(From submission cplusplus/draft#8787.)
References: common initial sequence and layout-compatible (11.4.1 [class.mem.general] paragraph 27)
Consider:
struct A { int x; };
struct B { int x; void foo(){} };
These types are not layout-compatible, because 11.4.1 [class.mem.general] paragraph 28 considers all members, not just non-static data members:
Two standard-layout struct (11.2 [class.prop]) types are layout-compatible classes if their common initial sequence comprises all members and bit-fields of both classes (6.9 [basic.types]).
Furthermore, the definition of layout-compatible unions is lacking consideration of bit-field length, [[no_unique_address]], and unnamed bit-fields.
Possible resolution:
Change in 6.9.1 [basic.types.general] paragraph 11 as follows:
Two types cv1 T1 and cv2 T2 are layout-compatible types if T1 and T2 are the same type, layout-compatible enumerations (9.8.1 [dcl.enum]), or layout-compatible standard-layout class types (11.2 [class.prop], 11.4 [class.mem]).
Remove 11.2 [class.prop] paragraph 4:
A standard-layout struct is a standard-layout class defined with the class-key struct or the class-key class. A standard-layout union is a standard-layout class defined with the class-key union.
Add a new paragraph before 11.4.1 [class.mem.general] paragraph 27, change paragraph 27 as follows and de-bulletize:
Two non-static data members or bit-fields are layout-compatible if
- they have layout-compatible types (6.9 [basic.types]),
- they have the same alignment requirements (6.8.3 [basic.align]),
- if a has-attribute-expression (15.2 [cpp.cond]) is not 0 for the no_unique_address attribute, then neither entity is declared with the no_unique_address attribute (9.13.11 [dcl.attr.nouniqueaddr]), and
- either both entities are bit-fields with the same width or neither is a bit-field.
The common initial sequence of two standard-layoutstructnon-union class (11.2 [class.prop]) types is the longest sequence of non-static data members and bit-fields in declaration order, starting with the first such entity in each of thestructsclasses, such that[ Example: ... ]
- corresponding entities
haveare layout-compatibletypes (6.9 [basic.types]),.- corresponding entities have the same alignment requirements (6.8.3 [basic.align]),
- if a has-attribute-expression (15.2 [cpp.cond]) is not 0 for the no_unique_address attribute, then neither entity is declared with the no_unique_address attribute (9.13.11 [dcl.attr.nouniqueaddr]), and
- either both entities are bit-fields with the same width or neither is a bit-field.
Change and merge in 11.4.1 [class.mem.general] paragraph 28 and paragraph 29 as follows:
Two standard-layoutstructclass (11.2 [class.prop]) types are layout-compatibleclassesif
- neither is a union and their common initial sequence comprises all non-static data members and bit-fields of both classes (6.9 [basic.types]) or
- both are unions and
Two standard-layout unions are layout-compatible ifthey have the same number of non-static data members and bit-fields and correspondingnon-static data membersentities (in any order)haveare layout-compatibletypes (6.9.1 [basic.types.general]).