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