-
Notifications
You must be signed in to change notification settings - Fork 15.4k
[clang] Implement __is_layout_compatible
#81506
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
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
52b2391
Initial implementation
Endilll 5599465
`Add another test for [[no_unique_address]]`
Endilll f0efbcc
Run clang-format
Endilll fcd987d
Drop "Sema" prefix on a function name
Endilll 7edd1fb
Add `const` qualifier to `Sema::IsLayoutCompatible()`
Endilll 1e71746
Remove changes to `ParseClassSpecifier()`
Endilll 3b42854
Double the number of SemaCXX tests, add DR tests
Endilll 58c1636
Add test with nested class type
Endilll 69243d4
Add test for forward declarations of enums
Endilll ec6d122
Add tests for VLAs, unions, incomplete, and abominable function types
Endilll c5a9c61
Add documentation bits
Endilll 4fcf3a3
Add tests for anonymous union
Endilll d4e15ed
Mention Jens' comment in enum tests
Endilll b33d3ca
Accept Corentin's changes to release notes
Endilll 42ad118
Remove trailing whitespaces
Endilll 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
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
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
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.
Some additional test cases to consider:
SomeStructandconst SomeStructvoid(int)andvoid(int)intandunsigned intare not layout compatiblecharandsigned char/unsigned charare not layout compatibleIf this catches bugs in the implementation of
isLayoutCompatible(), that' fine, we can document the current behavior in the test with a FIXME and come back to addressing the issues in a follow-up.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.
We do not yet implement https://cplusplus.github.io/CWG/issues/1719.html, so some tests are better deferred to the implementation of that DR
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.
I think we should add those tests somewhere (either here or in dr1xxx.cpp) so 1) we know we don't crash on them, 2) we're alerted to behavioral changes in this area, and 3) better documentation of existing behavior.
Uh oh!
There was an error while loading. Please reload this page.
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.
Done. It even works correctly for class types.
Done. I added tests for function types, reference to functions, pointers to function, pointers to data members, pointers to member functions.
We don't issue any, as far as I can see. And I don't think we can when the types are the same, ignoring cv qualifiers:
Done.
Agreed. I marked 1334 as superseded by 1719, and added a test for 1719.
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.
That's a bug, see https://eel.is/c++draft/tab:meta.rel#row-6-column-3-sentence-1: "T and U shall be complete types, cv void, or arrays of unknown bound."
but also: https://eel.is/c++draft/tab:meta.rel#row-6-column-3-sentence-1and http://eel.is/c++draft/class.mem#general-23 -- you can't test for layout compatibility if the class type is not complete because you don't know the members. So we should accept
voidbut notstruct NeverDefined.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.
This is possibly a defect (cplusplus/CWG#39 (comment), cplusplus/CWG#95 (comment)), but no CWG issue is filed yet.
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.
Thank you for mentioning that! I left a comment around enum tests.