1 #define MOZ_HEAP_CLASS __attribute__((annotate("moz_heap_class")))
2 #define MOZ_IMPLICIT __attribute__((annotate("moz_implicit")))
6 struct MOZ_HEAP_CLASS Heap
{
9 MOZ_IMPLICIT
Heap(int a
) {}
11 void *operator new(size_t x
) throw() { return 0; }
12 void *operator new(size_t blah
, char *buffer
) { return buffer
; }
16 struct MOZ_HEAP_CLASS TemplateClass
{
20 void gobble(void *) { }
22 void gobbleref(const Heap
&) { }
24 void misuseHeapClass(int len
) {
25 Heap invalid
; // expected-error {{variable of type 'Heap' only valid on the heap}} expected-note {{value incorrectly allocated in an automatic variable}}
26 Heap alsoInvalid
[2]; // expected-error {{variable of type 'Heap [2]' only valid on the heap}} expected-note {{value incorrectly allocated in an automatic variable}} expected-note {{'Heap [2]' is a heap type because it is an array of heap type 'Heap'}}
27 static Heap invalidStatic
; // expected-error {{variable of type 'Heap' only valid on the heap}} expected-note {{value incorrectly allocated in a global variable}}
28 static Heap alsoInvalidStatic
[2]; // expected-error {{variable of type 'Heap [2]' only valid on the heap}} expected-note {{value incorrectly allocated in a global variable}} expected-note {{'Heap [2]' is a heap type because it is an array of heap type 'Heap'}}
31 gobble(&invalidStatic
);
32 gobble(&alsoInvalid
[0]);
34 gobbleref(Heap()); // expected-error {{variable of type 'Heap' only valid on the heap}} expected-note {{value incorrectly allocated in a temporary}}
35 gobbleref(Heap(10, 20)); // expected-error {{variable of type 'Heap' only valid on the heap}} expected-note {{value incorrectly allocated in a temporary}}
36 gobbleref(Heap(10)); // expected-error {{variable of type 'Heap' only valid on the heap}} expected-note {{value incorrectly allocated in a temporary}}
37 gobbleref(10); // expected-error {{variable of type 'Heap' only valid on the heap}} expected-note {{value incorrectly allocated in a temporary}}
41 gobble(new TemplateClass
<int>);
42 gobble(len
<= 5 ? &invalid
: new Heap
);
44 char buffer
[sizeof(Heap
)];
45 gobble(new (buffer
) Heap
);
48 Heap invalidStatic
; // expected-error {{variable of type 'Heap' only valid on the heap}} expected-note {{value incorrectly allocated in a global variable}}
50 Heap nonstaticMember
; // expected-note {{'RandomClass' is a heap type because member 'nonstaticMember' is a heap type 'Heap'}}
51 static Heap staticMember
; // expected-error {{variable of type 'Heap' only valid on the heap}} expected-note {{value incorrectly allocated in a global variable}}
53 struct MOZ_HEAP_CLASS RandomHeapClass
{
55 static Heap staticMember
; // expected-error {{variable of type 'Heap' only valid on the heap}} expected-note {{value incorrectly allocated in a global variable}}
58 struct BadInherit
: Heap
{}; // expected-note {{'BadInherit' is a heap type because it inherits from a heap type 'Heap'}}
59 struct MOZ_HEAP_CLASS GoodInherit
: Heap
{};
61 void useStuffWrongly() {
62 BadInherit i
; // expected-error {{variable of type 'BadInherit' only valid on the heap}} expected-note {{value incorrectly allocated in an automatic variable}}
63 RandomClass r
; // expected-error {{variable of type 'RandomClass' only valid on the heap}} expected-note {{value incorrectly allocated in an automatic variable}}