是否有 C++11/14 替代 __attribute__((packed))

Is there a C++11/14 alternative to __attribute__((packed))

C++11 引入了标准化属性语法的概念。我找不到所有受支持属性的列表。是否有 C++11 属性替代 __attribute__((packed))

例如

struct __attribute__((packed)) Pack {
   uint8_t field1;
   uint8_t field2;
};

很遗憾,没有。标准当前定义的属性是:

  • [[noreturn]];
  • [[carries_dependency]];
  • [[deprecated]]/[[deprecated(reason)]];

其他一切都是实现定义的。