cpp-ru / ideas

Идеи по улучшению языка C++ для обсуждения
https://cpp-ru.github.io/proposals
Creative Commons Zero v1.0 Universal
89 stars 0 forks source link

standardize empty base/member optimization #542

Closed DaMilyutin closed 1 year ago

DaMilyutin commented 1 year ago

Idea We have EBO for empty base optimization. That reduces memory of object. In same way we have [[no_unique_address]] which does similar thing. However, this is not standadrized as behavior. (Or prove me wrong.)

What I'd like to see is default behavior is both for EBO/EMO.

I think we go wrong way using attributee for EMO where it should be default behavior. From other hand, we can add attribute [[unique_address]] for contrary behavior.

Examples `struct Empty { // methods, typedefs, static stuff... };

struct EmptyBase { // methods, typedefs, static stuff... }

struct Derived: EmptyBase // EBO kicks in by default { Data data; Empty empty; // EMO kicks in by default };

struct Derived: [[unique_address]] EmptyBase // attribute stops EBO { Data data; [[unique_address]] Empty empty; // attribute stops EMO };`

Smertig commented 1 year ago

It's an ABI break

apolukhin commented 1 year ago

The bahavior of [[no_unique_address]] is part of the Itanium ABI. It could be improved (see https://github.com/itanium-cxx-abi/cxx-abi/issues/77 for an example) however such improvements are ABI breaking.

So the best possible wording is already in place https://eel.is/c++draft/dcl.attr.nouniqueaddr , no way to improve it further without breaking things.