Clang 和 MSVC 报告同一结构的不同“sizeof”

Clang and MSVC report different `sizeof` for the same struct

叮当声:3.8.0 MSVC:19.00.24215.1 for x64

是什么导致了编译器之间的这种奇怪差异? MSVC 报告 12,但 Clang 报告 8!这里的 correct/expected 行为是什么?标准对此有何规定?

enum class CodeCompletionDeclKind {};

struct SwiftSemanticToken {
  unsigned ByteOffset;
  unsigned Length : 24;
  CodeCompletionDeclKind Kind : 6;
  bool IsRef : 1;
  bool IsSystem : 1;
};
static_assert(sizeof(SwiftSemanticToken) == 8, "Too big");

int main()
{
    std::cout << "Hello, world!\n";
}

包含位字段的 class 对象的大小将由实现定义。

class.bit/1:

...Allocation of bit-fields within a class object is implementation-defined. Alignment of bit-fields is implementation-defined. Bit-fields are packed into some addressable allocation unit. [ Note: Bit-fields straddle allocation units on some machines and not on others. Bit-fields are assigned right-to-left on some machines, left-to-right on others.  — end note ]