-
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
Add layout rule for [[no_unique_address]] (C++20 P0840R2) #50
Conversation
For exposition: the idea here is to use max(nvsize(D),dsize(D)) as the allocated size for potentially-overlapping data members of type D in the same way we use nvsize(D) as the allocated size for base classes. We previously only used dsize(D) as an intermediate value when laying out D, and now becomes part of the data propagated to other classes' layouts. We need to take the max of these two values because:
Note that there are corner cases where nvsize(C) > dsize(C)! This happens when we (strangely) increase nvsize(C) to include the complete size of an empty base class. (We do need to increase sizeof(C) for this case, but not nvsize(C).) Perhaps that's something we could consider fixing for ABI v2. The rules could be simplified slightly by setting dsize(C) = max(dsize(C), nvsize(C)) at the end of class layout, and then only using dsize(C) in recursive layouts, but it seems unreasonable to change the dsize for existing classes -- who knows what exciting uses people have found for it :) |
e6d4aa1
to
a187d15
Compare
a187d15
to
37ee702
Compare
@zygoloid, would you mind checking my merge and verifying that this change still reflects the right rule according to the standard? |
abi.html
Outdated
@@ -164,10 +164,15 @@ <h3><a href="#definitions"> 1.1 Definitions </a></h3> | |||
<dt> <i>empty class</i> </dt> | |||
<dd> | |||
A class with no non-static data members, | |||
no unnamed bit-fields other than zero-width bit-fields, | |||
no unnamed bit-fields other than zero-width bit-fields and empty data members, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't the "empty data members" be a qualification on "no non-static data members" rather than "no unnamed bit-fields"?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, absolutely; that was a mistake introduced by my merge. Fixed.
Merged rule now looks good, thanks. |
Okay. I'll leave this open for a week for further comment. |
1 week, 4 weeks, eh. |
Fixes #49