Commit 8d9cef25 by Abseil Team Committed by Copybara-Service

Don't construct/destroy object twice

PiperOrigin-RevId: 446274314
Change-Id: Ibf641808c533a10e0aef8d1601095e539ae5c43a
parent cc04c0e0
......@@ -548,22 +548,23 @@ struct MinimalMockAllocator {
TEST(AllocatorTraits, FunctionsMinimal) {
int trace = 0;
int hint;
TestValue x(&trace);
alignas(TestValue) char buffer[sizeof(TestValue)];
auto* x = reinterpret_cast<TestValue*>(buffer);
MinimalMockAllocator mock;
using Traits = absl::allocator_traits<MinimalMockAllocator>;
EXPECT_CALL(mock, allocate(7)).WillRepeatedly(Return(&x));
EXPECT_CALL(mock, deallocate(&x, 7));
EXPECT_CALL(mock, allocate(7)).WillRepeatedly(Return(x));
EXPECT_CALL(mock, deallocate(x, 7));
EXPECT_EQ(&x, Traits::allocate(mock, 7));
EXPECT_EQ(x, Traits::allocate(mock, 7));
static_cast<void>(Traits::allocate(mock, 7, static_cast<const void*>(&hint)));
EXPECT_EQ(&x, Traits::allocate(mock, 7, static_cast<const void*>(&hint)));
Traits::deallocate(mock, &x, 7);
EXPECT_EQ(x, Traits::allocate(mock, 7, static_cast<const void*>(&hint)));
Traits::deallocate(mock, x, 7);
EXPECT_EQ(0, trace);
Traits::construct(mock, x, &trace);
EXPECT_EQ(1, trace);
Traits::construct(mock, &x, &trace);
EXPECT_EQ(2, trace);
Traits::destroy(mock, &x);
EXPECT_EQ(1, trace);
Traits::destroy(mock, x);
EXPECT_EQ(0, trace);
EXPECT_EQ(std::numeric_limits<size_t>::max() / sizeof(TestValue),
Traits::max_size(mock));
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment