Skip to content

Commit af2bec8

Browse files
committed
Add test
1 parent 4f114f2 commit af2bec8

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

llvm/unittests/Support/RecyclerTest.cpp

+19
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ struct Object1 {
1818
char Data[1];
1919
};
2020

21+
struct Object8 {
22+
char Data[8];
23+
};
24+
2125
class DecoratedMallocAllocator : public MallocAllocator {
2226
public:
2327
int DeallocCount = 0;
@@ -43,4 +47,19 @@ TEST(RecyclerTest, RecycleAllocation) {
4347
EXPECT_EQ(Allocator.DeallocCount, 2);
4448
}
4549

50+
TEST(RecyclerTest, MoveConstructor) {
51+
DecoratedMallocAllocator Allocator;
52+
Recycler<Object8> R;
53+
Object8 *A1 = R.Allocate(Allocator);
54+
Object8 *A2 = R.Allocate(Allocator);
55+
R.Deallocate(Allocator, A1);
56+
R.Deallocate(Allocator, A2);
57+
Recycler<Object8> R2(std::move(R));
58+
Object8 *A3 = R2.Allocate(Allocator);
59+
R2.Deallocate(Allocator, A3);
60+
R.clear(Allocator); // Should not deallocate anything as it was moved from.
61+
EXPECT_EQ(Allocator.DeallocCount, 0);
62+
R2.clear(Allocator);
63+
EXPECT_EQ(Allocator.DeallocCount, 2);
64+
}
4665
} // end anonymous namespace

0 commit comments

Comments
 (0)