http://gcc.gnu.org/bugzilla/show_bug.cgi?id=54740
Bug #: 54740 Summary: Empty base optimization gets confused when a member variable derives from the same empty base. Classification: Unclassified Product: gcc Version: unknown Status: UNCONFIRMED Severity: major Priority: P3 Component: c++ AssignedTo: unassig...@gcc.gnu.org ReportedBy: aveni...@google.com struct empty_base {}; struct another_empty_base {}; struct inner : empty_base {}; struct outer : empty_base { inner i_; }; int main(int, char **) { return sizeof(outer); } This returns 2; If you change outer to derive from another_empty_base, it returns 1 (which is correct). Whatever the correct result should be, they at least should be the same. I tried it on 4.7.2 and on 4.4.3 - same problem is present. The optimization flags don't seem to make any difference. Setting it to major, as this seems like a very common idiom and people expect empty base optimization to kick in in such cases. Andy. P.S. Just in case: partial output from my gcc -v: Using built-in specs. COLLECT_GCC=/<...>/stage-4.7.2/bin/gcc COLLECT_LTO_WRAPPER=/<...>/stage-4.7.2/bin/../libexec/gcc/x86_64-unknown-linux-gnu/4.7.2/lto-wrapper Target: x86_64-unknown-linux-gnu Configured with: ../gcc-4.7.2/configure --prefix=/<...>/stage-4.7.2 --with-gmp=/<...>/gmp-4.3.2/ --with-mpfr=/<...>/mpfr-3.0.0/ --with-mpc=/<...>/mpc-0.9/ --enable-languages=c,c++ Thread model: posix gcc version 4.7.2 (GCC) It's a ubuntu-based system.