Clear moved from memory buffer

This commit is contained in:
Victor Zverovich 2022-02-20 08:12:19 -08:00
parent ea3d326c63
commit cbc59ca893
2 changed files with 5 additions and 3 deletions

View File

@ -775,6 +775,7 @@ class basic_memory_buffer final : public detail::buffer<T> {
// Set pointer to the inline array so that delete is not called
// when deallocating.
other.set(other.store_, 0);
other.clear();
}
this->resize(size);
}
@ -2896,7 +2897,7 @@ template <typename Enum, FMT_ENABLE_IF(std::is_enum<Enum>::value)>
constexpr auto format_as(Enum e) noexcept -> underlying_t<Enum> {
return static_cast<underlying_t<Enum>>(e);
}
}
} // namespace enums
#ifdef __cpp_lib_byte
inline auto format_as(std::byte b) -> unsigned char { return underlying(b); }

View File

@ -250,8 +250,9 @@ TEST(memory_buffer_test, move_ctor_dynamic_buffer) {
buffer.push_back('a');
basic_memory_buffer<char, 4, std_allocator> buffer2(std::move(buffer));
// Move should rip the guts of the first buffer.
EXPECT_EQ(inline_buffer_ptr, &buffer[0]);
EXPECT_EQ("testa", std::string(&buffer2[0], buffer2.size()));
EXPECT_EQ(&buffer[0], inline_buffer_ptr);
EXPECT_EQ(buffer.size(), 0);
EXPECT_EQ(std::string(&buffer2[0], buffer2.size()), "testa");
EXPECT_GT(buffer2.capacity(), 4u);
}