Why is a class with multiple public access specifiers standard_layout?
<p>I was just playing around with g++, and I found that</p>

<pre><code>#include &lt;type_traits&gt;

class Foo {
public: int x;
public: char y;
public: double z;
};

static_assert(std::is_standard_layout&lt;Foo&gt;::value, "Foo is not standard layout");

int main() {}
</code></pre>

<p>Compiles just fine.</p>

<p>According to <a href="https://stackoverflow.com/a/11364029/956134">this</a> answer, <code>data members across access specifiers may be reordered in memory</code>. So there's no gaurantee that <code>x</code> has to actually be the first member of <code>Foo</code> when actually laid out in memory. The way I've defined <code>Foo</code>, <code>y</code> could actually be the first element right?</p>

<p>I thought standard layout meant that you could more or less understand how the bytes are laid out for the given type. Allowing fields in a standard layout type to be reordered in an arbitrary manner seems counterintuitive to me. Why is this allowed?</p>