5

私は C++20 の属性をいじってみましたが、型特性[[no_unique_address]]で使用すると興味深い動作が見つかりました。has_unique_object_representations

#include <type_traits>

struct Empty {};

struct A : public Empty {
    int x;
};

struct B {
    [[no_unique_address]] Empty e;
    int x;
};

static_assert (sizeof(A) == sizeof(int));
static_assert (sizeof(B) == sizeof(int));

static_assert(std::has_unique_object_representations_v<A>);
static_assert(std::has_unique_object_representations_v<B>);

GCC (トランク) と Clang (トランク) の両方で最後のアサーションのみが失敗します。私が知る限り、ここで異なる動作をする理由はAありません。B

これはコンパイラのバグですか、それともこの違いには理由がありますか?

4

0 に答える 0