summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Leon Scroggins <scroggo@google.com> 2022-12-05 15:13:23 +0000
committer Android (Google) Code Review <android-gerrit@google.com> 2022-12-05 15:13:23 +0000
commit3d54c455375408457044da0fb00c8196c4fc20b5 (patch)
treeeaf75169e3146c9b58c14ea6cd43c4846134f991
parent6c4e915cfc9b3716cde8d99b263f2dda1f52510d (diff)
parentb19461b1d185192958d9f7a5d155e2720e132526 (diff)
Merge "Prevent calling new ftl::Optional"
-rw-r--r--include/ftl/optional.h8
1 files changed, 8 insertions, 0 deletions
diff --git a/include/ftl/optional.h b/include/ftl/optional.h
index 7b02bac340..a818128c92 100644
--- a/include/ftl/optional.h
+++ b/include/ftl/optional.h
@@ -95,6 +95,14 @@ struct Optional final : std::optional<T> {
if (has_value()) return std::invoke(std::forward<F>(f), std::move(value()));
return R();
}
+
+ // Delete new for this class. Its base doesn't have a virtual destructor, and
+ // if it got deleted via base class pointer, it would cause undefined
+ // behavior. There's not a good reason to allocate this object on the heap
+ // anyway.
+ static void* operator new(size_t) = delete;
+ static void* operator new[](size_t) = delete;
+
};
template <typename T, typename U>