There are a lot of questions about accessing unallocated memory, which is clearly undefined behavior. But what about the following corner case.
Consider the following struct, which is aligned to 16 bytes, but occupies only 8 bytes from that:
struct alignas(16) A
{
float data[2]; // the remaining 8 bytes are unallocated
};
Now we access 16 bytes of data by SSE aligned load / store intrinsics:
__m128 test_load(const A &a)
{
return _mm_load_ps(a.data);
}
void test_store(A &a, __m128 v)
{
_mm_store_ps(a.data, v);
}
Is this also undefined behavior and should I use padding instead?
Anyway, since Intel intrinsics are not standard C++, is accessing a partly allocated but aligned memory block (not greater than the size of the alignment) undefined behavior in standard C++?
I address both the intrinsic case and standard C++ case. I'm interested in both of them.