Repository navigation
fix(folding): correct unique object rep checks [GH #327] #326
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
Merged
daveedvdv-nvidia
merged 1 commit into
edgcpp:main
from
jakub-labenski:has_unique_object_representations
Oct 23, 2026
+210
−191
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
src/pending_changes/gh-327-has-unique-object-representations.txt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| [GH #327] | ||
| __has_unique_object_representations fixes | ||
|
|
||
| A base class that declares no nonstatic data members of its own but inherits | ||
| some (and is therefore not empty) was treated as an empty base class. Its | ||
| size was then counted as tail padding, so the trait was incorrectly FALSE for | ||
| classes derived from it. For example, with --c++11: | ||
|
|
||
| struct A { char i; }; | ||
| struct B : A {}; | ||
| struct C : B {}; | ||
| static_assert(__has_unique_object_representations(C), ""); // Previously | ||
| // failed. | ||
|
|
||
| This is now fixed. In addition: | ||
|
|
||
| - An unnamed bit-field of nonzero width is now treated as padding, as the | ||
| standard requires, except in g++ modes before 13.1 (other than 10.5, | ||
| 11.4, and 12.3) and in Clang modes before 17. For example: | ||
|
|
||
| struct S { char a; char : 8; char b; }; | ||
| static_assert(!__has_unique_object_representations(S), ""); | ||
|
|
||
| - In a union, an unnamed bit-field overlaps the other members, so the | ||
| rule above does not apply; as before, a bit-field narrower than the | ||
| union is treated as padding, except in Clang modes. Microsoft mode now | ||
| also does not treat it as padding, matching MSVC. For example, | ||
| with --microsoft: | ||
|
|
||
| union U { int x : 3; }; | ||
| static_assert(__has_unique_object_representations(U), ""); | ||
|
|
||
| - Volatile-qualified non-class types (e.g., "volatile int") are treated as | ||
| not having unique object representations only in g++ modes before | ||
| version 10 (previously this was done for all g++ versions, including | ||
| Clang modes). |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Does that need to be restricted to non-union class types?
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, it should. In a union, an unnamed bit-field overlaps the other members, so it shouldn't be treated as padding on its own. Instead, any bit-field narrower than the union is treated as padding, except in Clang and Microsoft modes (which ignore that case). This is now implemented and tests have been added.