`reinterpred_cast` between unrelated structs
Let's say I have two unrelated structs A and B which have exactly the same data members and everything. Checked with a static assert like this:
template
constexpr bool CheckCompatibility() noexcept
{
static_assert(sizeof(From) == sizeof(To));
static_assert(alignof(From) == alignof(To));
static_assert(std::is_standard_layout_v);
static_assert(std::is_standard_layout_v);
static_assert(std::is_trivially_destructible_v);
static_assert(std::is_trivially_destructible_v);
static_assert(std::is_trivially_copyable_v);
static_assert(std::is_trivially_copyable_v);
return true;
}
Would this be allowed or UB?
struct A{
int x,
float y,
double z,
int arr[3];
};
struct B{
int x,
float y,
double z,
int arr[3];
};
A* a = new A();
B* b = reinterpret_cast(a);
// Using a & b (with proper synchronization and so on)