Copy absl::WrapUnique()'s static_asserts into pdfium::WrapUnique()
Add more checks to actually enforce the guidance in the function
comments. Use the static_asserts from absl::WrapUnique() in
third_party/abseil-cpp/absl/memory/memory.h.
Change-Id: Ia32e0f5f27636290943d18e401c71977e6ebb608
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/116732
Reviewed-by: Tom Sepez <tsepez@chromium.org>
Reviewed-by: Thomas Sepez <tsepez@google.com>
Commit-Queue: Lei Zhang <thestig@chromium.org>
diff --git a/core/fxcrt/ptr_util.h b/core/fxcrt/ptr_util.h
index 7fbaeae..8bebeb3 100644
--- a/core/fxcrt/ptr_util.h
+++ b/core/fxcrt/ptr_util.h
@@ -6,6 +6,7 @@
#define CORE_FXCRT_PTR_UTIL_H_
#include <memory>
+#include <type_traits>
namespace pdfium {
@@ -14,6 +15,8 @@
// std::unique_ptr<T[]>: do not use this helper for array allocations.
template <typename T>
std::unique_ptr<T> WrapUnique(T* ptr) {
+ static_assert(!std::is_array<T>::value, "array types are unsupported");
+ static_assert(std::is_object<T>::value, "non-object types are unsupported");
return std::unique_ptr<T>(ptr);
}