This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/63579] New: New attribute for empty member optimization
- From: "glisse at gcc dot gnu.org" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Fri, 17 Oct 2014 17:18:12 +0000
- Subject: [Bug c++/63579] New: New attribute for empty member optimization
- Auto-submitted: auto-generated
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=63579
Bug ID: 63579
Summary: New attribute for empty member optimization
Product: gcc
Version: 5.0
Status: UNCONFIRMED
Severity: enhancement
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: glisse at gcc dot gnu.org
Hello,
I am getting a bit sick of all the artificial base classes invented just so we
can benefit from the empty base optimization when we actually want a member. I
believe an attribute would be a nice way to work around this standard
misfeature:
template <class T1, class T2>
struct compressed_pair
{
T1 t1 [[gnu::empty]];
T2 t2 [[gnu::empty]];
// ... all the member functions
};
struct Empty { };
static_assert (sizeof (compressed_pair<int, Empty>) == sizeof (int), "too
long");
To be more specific, I was thinking of having the attribute mean: if the type
is a class type, for layout purposes pretend it is appended at the end of the
list of base classes (it also has an impact on non-empty members). But any
variant would do, as long as it stops being interesting to put a class as a
base instead of a member. The layout code handles bases differently enough that
it doesn't look as easy to implement as I had hoped. I'll attach a hack that I
am playing with.
We will also hit the ABI misfeature that means that in layout_empty_base we
only test offset 0 before jumping to eoc without testing offsets alignment,
2*alignment, etc. But that's another fight...