https://gcc.gnu.org/bugzilla/show_bug.cgi?id=87258
Bug ID: 87258 Summary: vector<bool> useless offset Product: gcc Version: 9.0 Status: UNCONFIRMED Keywords: ABI, missed-optimization Severity: normal Priority: P3 Component: libstdc++ Assignee: unassigned at gcc dot gnu.org Reporter: glisse at gcc dot gnu.org Target Milestone: --- Hello, I guess nobody will care much since this is vector<bool>, but I don't understand why _M_start is a _Bit_iterator. This means that it includes a useless _M_offset that is always 0 (that's easy to check since operator[] ignores it). It wastes some space. And since begin() returns _M_start, it also makes it hard for the compiler to know that the beginning offset is always 0, and we often generate a lot of dead code to handle the non-zero case. Removing the offset would break the ABI, so I guess that's not going to fly. (_M_finish is also not very space efficient with pointer+length where just the size would work, but maybe it is faster?) As a comparison, sizeof(vector<bool>) is 40 with libstdc++ and 24 with libc++ on x86_64 linux. Maybe begin could return _Bit_iterator(_M_start._M_p, 0) instead of _M_start to give more information to the compiler?