Add test_reference.cpp

This commit is contained in:
2025-09-10 22:05:31 -04:00
parent 6aaca4c171
commit b9106a0d3c
3 changed files with 220 additions and 2 deletions

View File

@@ -385,9 +385,14 @@ template <typename T, typename... Args> Ref<T> make_ref(Args &&...args) {
constexpr size_t padded_cb_size =
(cb_size + alignment - 1) & ~(alignment - 1);
constexpr size_t total_alignment =
std::max(alignof(detail::ControlBlock), alignment);
constexpr size_t total_size = padded_cb_size + sizeof(T);
constexpr size_t aligned_total_size =
(total_size + total_alignment - 1) & ~(total_alignment - 1);
char *buf = reinterpret_cast<char *>(
std::aligned_alloc(std::max(alignof(detail::ControlBlock), alignment),
padded_cb_size + sizeof(T)));
std::aligned_alloc(total_alignment, aligned_total_size));
if (!buf) {
std::fprintf(stderr, "Out of memory\n");
std::abort();