Bug 1523562 [wpt PR 14965] - Sync Mozilla CSS tests as of 2019-01-20, a=testonly
[gecko.git] / build / clang-plugin / tests / TestHeapClass.cpp
blob36e7629737221e6854666c8a521c6a1f988f5387
1 #define MOZ_HEAP_CLASS __attribute__((annotate("moz_heap_class")))
2 #define MOZ_IMPLICIT __attribute__((annotate("moz_implicit")))
4 #include <stddef.h>
6 struct MOZ_HEAP_CLASS Heap {
7 int i;
8 Heap() {}
9 MOZ_IMPLICIT Heap(int a) {}
10 Heap(int a, int b) {}
11 void *operator new(size_t x) throw() { return 0; }
12 void *operator new(size_t blah, char *buffer) { return buffer; }
15 template <class T>
16 struct MOZ_HEAP_CLASS TemplateClass {
17 T i;
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'}}
30 gobble(&invalid);
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}}
39 gobble(new Heap);
40 gobble(new Heap[10]);
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}}
49 struct RandomClass {
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 {
54 Heap nonstaticMember;
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}}