Inconsistency in has_unique_object_representations and empty subobjects
07:28 04 Oct 2020

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 

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);
static_assert(std::has_unique_object_representations_v);

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?

c++ c++20 type-traits object-identity