inheritance and attribute packed
<p>Consider this code in C++</p>

<pre><code>struct Base
{
   std::int64_t x;
   std::int64_t y;
};
static_assert(sizeof(Base) == 16, "Base not of size 16!");

struct Derived : Base
{
   std::int32_t z;
}__attribute__((packed));
static_assert(sizeof(Derived) == 20, "Derived not of size 20!");
</code></pre>

<p>clang considers this code valid, where as gcc results in firing of the second static_assert. ("Derived not of size 20!). If I add attribute packed in Base as well, then it is fine in both the compilers. Does anyone know which one is right and why?</p>