Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions clang/lib/AST/ByteCode/Pointer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,8 @@ size_t Pointer::computeOffsetForComparison() const {
}

if (const Record *R = P.getBase().getRecord(); R && R->isUnion()) {
if (P.isOnePastEnd())
++Result;
// Direct child of a union - all have offset 0.
P = P.getBase();
continue;
Expand Down
12 changes: 12 additions & 0 deletions clang/test/AST/ByteCode/unions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -966,3 +966,15 @@ namespace AddressComparison {
static_assert(&U2.a[0] != &U2.b[1]);
static_assert(&U2.a[0] == &U2.b[1]); // both-error {{failed}}
}

#if __cplusplus >= 202002L
namespace UnionMemberOnePastEnd {
constexpr bool b() {
union {
int p;
};
return &p == (&p + 1);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we have a test that shows it fails for return &p == (&p + 2);?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not in this specific configuration I think, but we have plenty of tests for the "cannot refer to element 2 of non-array object" diagnostic.

}
static_assert(!b());
}
#endif