Commit a600a843 authored by Tobias Tebbi's avatar Tobias Tebbi Committed by Commit Bot

[base] Add compile-time error when Zone* is used for plain placement new.

Bug: 
Change-Id: Idca921bde6f10d8e9809c0b3a83cc3a8d3f135af
Reviewed-on: https://chromium-review.googlesource.com/779424
Commit-Queue: Tobias Tebbi <tebbi@chromium.org>
Reviewed-by: 's avatarClemens Hammacher <clemensh@chromium.org>
Cr-Commit-Position: refs/heads/master@{#49676}
parent 6ea63a12
...@@ -314,4 +314,17 @@ typedef base::CustomMatcherTemplateHashMapImpl<ZoneAllocationPolicy> ...@@ -314,4 +314,17 @@ typedef base::CustomMatcherTemplateHashMapImpl<ZoneAllocationPolicy>
} // namespace internal } // namespace internal
} // namespace v8 } // namespace v8
// The accidential pattern
// new (zone) SomeObject()
// where SomeObject does not inherit from ZoneObject leads to nasty crashes.
// This triggers a compile-time error instead.
template <class T, typename = typename std::enable_if<std::is_convertible<
T, const v8::internal::Zone*>::value>::type>
void* operator new(size_t size, T zone) {
static_assert(false && sizeof(T),
"Placement new with a zone is only permitted for classes "
"inheriting from ZoneObject");
UNREACHABLE();
}
#endif // V8_ZONE_ZONE_H_ #endif // V8_ZONE_ZONE_H_
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment