mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-01 14:45:29 +00:00
f39213113a
--HG-- extra : rebase_source : 1ea94cf7a8ab7207d238c65877001549f3f828be
29 lines
811 B
C++
29 lines
811 B
C++
#define MOZ_NONHEAP_CLASS __attribute__((annotate("moz_nonheap_class")))
|
|
#define MOZ_HEAP_ALLOCATOR \
|
|
_Pragma("GCC diagnostic push") \
|
|
_Pragma("GCC diagnostic ignored \"-Wgcc-compat\"") \
|
|
__attribute__((annotate("moz_heap_allocator"))) \
|
|
_Pragma("GCC diagnostic pop")
|
|
|
|
#include <stdlib.h>
|
|
#include <memory>
|
|
|
|
struct MOZ_NONHEAP_CLASS X {
|
|
};
|
|
|
|
void *operator new(size_t x, int qual) MOZ_HEAP_ALLOCATOR {
|
|
return ::operator new(x);
|
|
}
|
|
|
|
template <typename T>
|
|
T *customAlloc() MOZ_HEAP_ALLOCATOR {
|
|
T *arg = static_cast<T*>(malloc(sizeof(T)));
|
|
return new (arg) T();
|
|
}
|
|
|
|
template <typename T>
|
|
void misuseX(T q) {
|
|
X *foo = customAlloc<X>(); // expected-error {{variable of type 'X' is not valid on the heap}}
|
|
X *foo2 = new (100) X(); // expected-error {{variable of type 'X' is not valid on the heap}}
|
|
}
|