-
Notifications
You must be signed in to change notification settings - Fork 14.6k
[Clang] Make enums trivially equality comparable #133587
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3873,6 +3873,11 @@ static_assert(!__is_trivially_equality_comparable(NonTriviallyEqualityComparable | |
|
||
#if __cplusplus >= 202002L | ||
|
||
enum TriviallyEqualityComparableEnum { | ||
x, y | ||
}; | ||
static_assert(__is_trivially_equality_comparable(TriviallyEqualityComparableEnum)); | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is very nice, thank you! At line 3853 add:
It would be beneficial also to test that the compiler does not crash in this case:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not convinced that it's a good idea to test behaviour that's UB. AFAICT we don't have a test like this for any other trait. |
||
struct TriviallyEqualityComparable { | ||
int i; | ||
int j; | ||
|
@@ -3891,6 +3896,13 @@ struct TriviallyEqualityComparableContainsArray { | |
}; | ||
static_assert(__is_trivially_equality_comparable(TriviallyEqualityComparableContainsArray)); | ||
|
||
struct TriviallyEqualityComparableContainsEnum { | ||
TriviallyEqualityComparableEnum e; | ||
|
||
bool operator==(const TriviallyEqualityComparableContainsEnum&) const = default; | ||
}; | ||
static_assert(__is_trivially_equality_comparable(TriviallyEqualityComparableContainsEnum)); | ||
|
||
struct TriviallyEqualityComparableContainsMultiDimensionArray { | ||
int a[4][4]; | ||
|
||
|
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.
It looks like you are currently only testing if it is defaulted, we should be testing all code paths if possible to insure this does what we expect and to prevent future regressions.
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'm not sure what you're referring to. If you mean I should test a non-trivially equality comparable enum, that's already there.
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 am probably being dense here but I thought for the both the test cases below
EqualityComparisonIsDefaulted
would returntrue
so I was asking if there is a test case in which it returnsfalse
.