diff --git a/tensorflow/lite/core/api/flatbuffer_conversions.cc b/tensorflow/lite/core/api/flatbuffer_conversions.cc index 4441494622a..998b7d5fbf1 100644 --- a/tensorflow/lite/core/api/flatbuffer_conversions.cc +++ b/tensorflow/lite/core/api/flatbuffer_conversions.cc @@ -49,7 +49,7 @@ class SafeBuiltinDataAllocator { template BuiltinDataPtr Allocate() { - return BuiltinDataPtr(allocator_->AllocateStruct(), + return BuiltinDataPtr(allocator_->AllocatePOD(), BuiltinDataDeleter(allocator_)); } diff --git a/tensorflow/lite/core/api/flatbuffer_conversions.h b/tensorflow/lite/core/api/flatbuffer_conversions.h index cb1b16344de..a6ed2e92dad 100644 --- a/tensorflow/lite/core/api/flatbuffer_conversions.h +++ b/tensorflow/lite/core/api/flatbuffer_conversions.h @@ -32,15 +32,14 @@ class BuiltinDataAllocator { virtual void* Allocate(size_t size) = 0; virtual void Deallocate(void* data) = 0; - // Allocate a structure, but make sure it is trivially destructible. The - // reason we do this, is that Interpreter's C extension part will take - // ownership so destructors will not be run during deallocation. + // Allocate a structure, but make sure it is a POD structure that doesn't + // require constructors to run. The reason we do this, is that Interpreter's C + // extension part will take ownership so destructors will not be run during + // deallocation. template - T* AllocateStruct() { - static_assert(std::is_trivially_destructible::value, - "Builtin data structure must be trivially destructible."); - void* allocated_memory = this->Allocate(sizeof(T)); - return new (allocated_memory) T; + T* AllocatePOD() { + static_assert(std::is_pod::value, "Builtin data structure must be POD."); + return static_cast(this->Allocate(sizeof(T))); } virtual ~BuiltinDataAllocator() {}