Nit: In C++, you need to call the constructor to start a lifetime of an object, or else it is undefined behavior (even though in practice, with many compilers you can simply static_cast raw memory to an object with trivial constructors). Fix this within AllocatePOD by calling placement new. For objects with trivial constructors (PODs included), this is no-op.

PiperOrigin-RevId: 307086589
Change-Id: I5d4984f2e4bca17908245370c4581d46428a21c6
diff --git a/tensorflow/lite/core/api/flatbuffer_conversions.h b/tensorflow/lite/core/api/flatbuffer_conversions.h
index a6ed2e9..df1ada8 100644
--- a/tensorflow/lite/core/api/flatbuffer_conversions.h
+++ b/tensorflow/lite/core/api/flatbuffer_conversions.h
@@ -39,7 +39,8 @@
   template <typename T>
   T* AllocatePOD() {
     static_assert(std::is_pod<T>::value, "Builtin data structure must be POD.");
-    return static_cast<T*>(this->Allocate(sizeof(T)));
+    void* allocated_memory = this->Allocate(sizeof(T));
+    return new (allocated_memory) T;
   }
 
   virtual ~BuiltinDataAllocator() {}