In c++20.
Consider
class A{
int v;
};
static_assert(std::is_standard_layout_v<A> == true);
A a{};
Then, we know &a==&(a.v)
. I'm wondering, is sizeof(A)==sizeof(int)//or a.v
guaranteed to be true by standard(it's true for GCC and clang)? A
only have 1 member variable of fundamental type.
It is not guaranteed.
For standard-layout classes the first member (and base classes) is located at offset zero as you noted, but there is no guarantee or requirement for there not to be padding after the member or at the end of the class.