-
Notifications
You must be signed in to change notification settings - Fork 85
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[[no_unique_address]] with duplicate type #75
Comments
The current rule is consistent with the rule for base classes:
If we used the So we need to decide which we care more about: that a sequence of bases can be transformed into a sequence of [[no_unique_address]] members with no change in layout (which we can only guarantee in the absence of dynamic base classes, due to the special layout rules for virtual bases and primary base classes), or that we don't waste space on empty Here is perhaps a more compelling example justifying the current approach:
It is desirable for the layout of
... but if we consider placing Perhaps we could consider additional offsets only for |
Filed #77 to capture that we should consider nonzero offsets within the class when performing EBO. |
The current specification produces suboptimal layouts for classes where two non-static member variables of the same empty type use
[[no_unique_address]]
.In #49 and in the paper introducing the feature it was noted that in order to allow existing code to easily transition to
[[no_unique_address]]
, the layout should be the same as if empty base classes had been used, where applicable.In the case of two instances of the same type however, no base classes could have previously been used, as a class may not directly have two of the same base class.
Here an optimal layout is produced:
The same layout can be produced, and is already being produced by GCC and Clang, without
[[no_unique_address]]
:However moving the
int
variable to the front changes things:So it is this case where two non-static member variables of the same empty type, adorned with
[[no_unique_address]]
, are placed not at the front of the class, which produces a suboptimal layout when another layout, already being used in other cases, would do.The text was updated successfully, but these errors were encountered: