C++ Logo

std-discussion

Advanced search

Re: Shouldn't members need equal alignments to be in the common initial sequence?

From: Jens Maurer <Jens.Maurer_at_[hidden]>
Date: Mon, 2 May 2022 13:06:04 +0200
On 02/05/2022 03.29, Brian Bi via Std-Discussion wrote:
> The standard has the following to say about the common initial sequence, [class.mem.general] paragraphs 23 through 26:
>
> The common initial sequence of two standard-layout struct ([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 the structs, such that corresponding entities have layout-compatible types ([basic.types]), either both entities are declared with the no_­unique_­address attribute ([dcl.attr.nouniqueaddr]) or neither is, and either both entities are bit-fields with the same width or neither is a bit-field.

[...]

> There is no requirement that corresponding non-static members have the same alignment, so it appears that these two structs are layout-compatible, for example:

Yes, that looks like a bug in the standard.

If you have a github account, feel free to create an issue here:

https://github.com/cplusplus/CWG/issues

Jens

Received on 2022-05-02 11:06:09