- The following stripped code trigger a gcc-4.8 bug. To work that around, move the alignment evaluation into template parameter.
// https://godbolt.org/z/58p5_X
//
#include <cstddef>
#include <cstdint>
enum { aligned = 0, unaligned = 1 };
template <typename T, int alignment> struct PickAlignment {
enum { value = alignment == 0 ? alignof(T) : alignment };
};
template <typename ValueType, std::size_t Alignment> struct packed {
private:
struct {
alignas(
PickAlignment<ValueType, Alignment>::value) char buffer[sizeof(int)];
} Value;
};
using ule16_t = packed<uint16_t, unaligned>;
ule16_t x;- Also, replace alignas with LLVMALIGN_AS to improve the compiler compatibility.