Skip to content

Commit 328c146

Browse files
committed
[ptrintenum] Cleanup equality method.
1 parent 0652b3a commit 328c146

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

include/swift/Basic/PointerIntEnum.h

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -160,12 +160,7 @@ class PointerIntEnum {
160160
bool isValid() const { return Storage != InvalidStorage; }
161161

162162
bool operator==(const PointerIntEnum &Other) const {
163-
// If this value is not valid, it can only equal another invalid
164-
// PointerIntEnum.
165-
if (!isValid())
166-
return !Other.isValid();
167-
168-
// Otherwise just compare the raw storage.
163+
// Just compare the raw storage.
169164
return Other.Storage == Storage;
170165
}
171166

unittests/Basic/PointerIntEnumTest.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,16 @@ TEST(PointerIntEnumTest, Comparisons) {
234234
// Test that pointers and indices compare differently.
235235
EXPECT_NE(IndexCase1, PtrCase1);
236236

237+
// Test comparison in between invalid and valid PointerIntEnums.
238+
PointerIntEnumTy Invalid1;
239+
PointerIntEnumTy Invalid2;
240+
EXPECT_EQ(Invalid1, Invalid2);
241+
EXPECT_NE(Invalid1, IndexCase1);
242+
EXPECT_NE(Invalid1, PtrCase1);
243+
EXPECT_NE(IndexCase1, Invalid1);
244+
EXPECT_NE(PtrCase1, Invalid1);
245+
246+
237247
delete[] data2;
238248
delete[] data1;
239249
}

0 commit comments

Comments
 (0)