diff --git a/hwy/aligned_allocator.h b/hwy/aligned_allocator.h index 6274c5d192..19a3ce05f7 100644 --- a/hwy/aligned_allocator.h +++ b/hwy/aligned_allocator.h @@ -232,7 +232,6 @@ class AlignedFreer { template void operator()(T* aligned_pointer) const { - // TODO(deymo): assert that we are using a POD type T. FreeAlignedBytes(aligned_pointer, free_, opaque_ptr_); } @@ -251,6 +250,8 @@ using AlignedFreeUniquePtr = std::unique_ptr; template AlignedFreeUniquePtr AllocateAligned(const size_t items, AllocPtr alloc, FreePtr free, void* opaque) { + static_assert(std::is_trivial::value && std::is_standard_layout::value, + "Can only allocate POD structs"); return AlignedFreeUniquePtr( detail::AllocateAlignedItems(items, alloc, opaque), AlignedFreer(free, opaque)); diff --git a/hwy/aligned_allocator_test.cc b/hwy/aligned_allocator_test.cc index 83e77534a3..9994c5594e 100644 --- a/hwy/aligned_allocator_test.cc +++ b/hwy/aligned_allocator_test.cc @@ -145,8 +145,8 @@ TEST(AlignedAllocatorTest, TestEmptyAlignedUniquePtr) { } TEST(AlignedAllocatorTest, TestEmptyAlignedFreeUniquePtr) { - AlignedFreeUniquePtr> ptr(nullptr, AlignedFreer()); - AlignedFreeUniquePtr[]> arr(nullptr, AlignedFreer()); + AlignedFreeUniquePtr> ptr(nullptr, AlignedFreer()); + AlignedFreeUniquePtr[]> arr(nullptr, AlignedFreer()); } TEST(AlignedAllocatorTest, TestCustomAlloc) { @@ -228,19 +228,6 @@ TEST(AlignedAllocatorTest, TestAllocMultipleInt) { HWY_ASSERT(ret != size_t{0}); } -TEST(AlignedAllocatorTest, TestAllocateAlignedObjectWithoutDestructor) { - int counter = 0; - { - // This doesn't call the constructor. - auto obj = AllocateAligned>(1); - HWY_ASSERT(obj); - obj[0].counter_ = &counter; - } - // Destroying the unique_ptr shouldn't have called the destructor of the - // SampleObject<24>. - HWY_ASSERT_EQ(0, counter); -} - TEST(AlignedAllocatorTest, TestMakeUniqueAlignedArrayWithCustomAlloc) { FakeAllocator fake_alloc; int counter = 0;