Inconsistency in has_unique_object_representations and empty subobjects

241 views Asked by At

I've playing around with C++20's [[no_unique_address]] attribute and found some interesting behavior when using it with the has_unique_object_representations type trait:

#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>);

Only the last assertion fails with both GCC (trunk) and Clang (trunk). As far as I can tell, there's no reason for A and B to behave differently here.

Is this a compiler bug or is there a reason for this difference?

0

There are 0 answers