This makes the tests more minimal, and in particular it avoids relying on a complete `<cstdlib>`, which may not be available on all platforms.
Differential Revision: https://reviews.llvm.org/D137188
#include <memory_resource>
#include <cassert>
-#include <cstdlib>
#include <tuple>
#include <type_traits>
#include <utility>
typedef default_constructible T;
typedef std::pair<T, T> P;
typedef std::pmr::polymorphic_allocator<void> A;
- P* ptr = (P*)std::malloc(sizeof(P));
+ alignas(P) char buffer[sizeof(P)];
+ P* ptr = reinterpret_cast<P*>(buffer);
A a;
a.construct(ptr);
assert(constructed == 2);
assert(ptr->first.x == 42);
assert(ptr->second.x == 42);
- std::free(ptr);
}
return 0;
#include <type_traits>
#include <utility>
#include <cassert>
-#include <cstdlib>
#include "test_macros.h"
PMA pma(std::pmr::new_delete_resource());
{
using Pair = std::pair<W1, W2>;
- void* where = std::malloc(sizeof(Pair));
- Pair* p = (Pair*)where;
+ alignas(Pair) char buffer[sizeof(Pair)];
+ Pair* p = reinterpret_cast<Pair*>(buffer);
pma.construct(p, std::piecewise_construct, std::make_tuple(42), std::make_tuple(42));
assert(p->first.holds(42, pma));
assert(p->second.holds(42, pma));
pma.destroy(p);
- std::free(where);
}
}
#include <memory_resource>
#include <cassert>
-#include <cstdlib>
#include <new>
#include <type_traits>
ASSERT_SAME_TYPE(decltype(a.destroy((destroyable*)nullptr)), void);
}
{
- destroyable* ptr = ::new (std::malloc(sizeof(destroyable))) destroyable();
+ alignas(destroyable) char buffer[sizeof(destroyable)];
+ destroyable* ptr = ::new (buffer) destroyable();
assert(count == 1);
A{}.destroy(ptr);
assert(count == 0);
- std::free(ptr);
}
return 0;