1 #define MOZ_STACK_CLASS __attribute__((annotate("moz_stack_class")))
4 struct MOZ_STACK_CLASS Stack
{
6 void *operator new(size_t x
) throw() { return 0; }
7 void *operator new(size_t blah
, char *buffer
) { return buffer
; }
11 struct MOZ_STACK_CLASS TemplateClass
{
15 void gobble(void *) { }
17 void misuseStackClass(int len
) {
20 static Stack notValid
; // expected-error {{variable of type 'Stack' only valid on the stack}} expected-note {{value incorrectly allocated in a global variable}}
21 static Stack alsoNotValid
[2]; // expected-error-re {{variable of type 'Stack{{ ?}}[2]' only valid on the stack}} expected-note-re {{'Stack{{ ?}}[2]' is a stack type because it is an array of stack type 'Stack'}} expected-note {{value incorrectly allocated in a global variable}}
25 gobble(&alsoValid
[0]);
27 gobble(new Stack
); // expected-error {{variable of type 'Stack' only valid on the stack}} expected-note {{value incorrectly allocated on the heap}}
28 gobble(new Stack
[10]); // expected-error {{variable of type 'Stack' only valid on the stack}} expected-note {{value incorrectly allocated on the heap}}
29 gobble(new TemplateClass
<int>); // expected-error {{variable of type 'TemplateClass<int>' only valid on the stack}} expected-note {{value incorrectly allocated on the heap}}
30 gobble(len
<= 5 ? &valid
: new Stack
); // expected-error {{variable of type 'Stack' only valid on the stack}} expected-note {{value incorrectly allocated on the heap}}
32 char buffer
[sizeof(Stack
)];
33 gobble(new (buffer
) Stack
);
36 Stack notValid
; // expected-error {{variable of type 'Stack' only valid on the stack}} expected-note {{value incorrectly allocated in a global variable}}
38 Stack nonstaticMember
; // expected-note {{'RandomClass' is a stack type because member 'nonstaticMember' is a stack type 'Stack'}}
39 static Stack staticMember
; // expected-error {{variable of type 'Stack' only valid on the stack}} expected-note {{value incorrectly allocated in a global variable}}
41 struct MOZ_STACK_CLASS RandomStackClass
{
42 Stack nonstaticMember
;
43 static Stack staticMember
; // expected-error {{variable of type 'Stack' only valid on the stack}} expected-note {{value incorrectly allocated in a global variable}}
46 struct BadInherit
: Stack
{}; // expected-note {{'BadInherit' is a stack type because it inherits from a stack type 'Stack'}}
47 struct MOZ_STACK_CLASS GoodInherit
: Stack
{};
49 BadInherit moreInvalid
; // expected-error {{variable of type 'BadInherit' only valid on the stack}} expected-note {{value incorrectly allocated in a global variable}}
50 RandomClass evenMoreInvalid
; // expected-error {{variable of type 'RandomClass' only valid on the stack}} expected-note {{value incorrectly allocated in a global variable}}