1 #define MOZ_NON_TEMPORARY_CLASS __attribute__((annotate("moz_non_temporary_class")))
2 #define MOZ_IMPLICIT __attribute__((annotate("moz_implicit")))
6 struct MOZ_NON_TEMPORARY_CLASS NonTemporary
{
9 MOZ_IMPLICIT
NonTemporary(int a
) {}
10 NonTemporary(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
; }
16 struct MOZ_NON_TEMPORARY_CLASS TemplateClass
{
20 void gobble(void *) { }
22 void gobbleref(const NonTemporary
&) { }
25 void gobbleanyref(const T
&) { }
27 void misuseNonTemporaryClass(int len
) {
29 NonTemporary alsoInvalid
[2];
30 static NonTemporary invalidStatic
;
31 static NonTemporary alsoInvalidStatic
[2];
34 gobble(&invalidStatic
);
35 gobble(&alsoInvalid
[0]);
37 gobbleref(NonTemporary()); // expected-error {{variable of type 'NonTemporary' is not valid in a temporary}} expected-note {{value incorrectly allocated in a temporary}}
38 gobbleref(NonTemporary(10, 20)); // expected-error {{variable of type 'NonTemporary' is not valid in a temporary}} expected-note {{value incorrectly allocated in a temporary}}
39 gobbleref(NonTemporary(10)); // expected-error {{variable of type 'NonTemporary' is not valid in a temporary}} expected-note {{value incorrectly allocated in a temporary}}
40 gobbleref(10); // expected-error {{variable of type 'NonTemporary' is not valid in a temporary}} expected-note {{value incorrectly allocated in a temporary}}
41 gobbleanyref(TemplateClass
<int>()); // expected-error {{variable of type 'TemplateClass<int>' is not valid in a temporary}} expected-note {{value incorrectly allocated in a temporary}}
43 gobble(new NonTemporary
);
44 gobble(new NonTemporary
[10]);
45 gobble(new TemplateClass
<int>);
46 gobble(len
<= 5 ? &invalid
: new NonTemporary
);
48 char buffer
[sizeof(NonTemporary
)];
49 gobble(new (buffer
) NonTemporary
);
52 void defaultArg(const NonTemporary
& arg
= NonTemporary()) {
55 NonTemporary invalidStatic
;
57 NonTemporary nonstaticMember
; // expected-note {{'RandomClass' is a non-temporary type because member 'nonstaticMember' is a non-temporary type 'NonTemporary'}}
58 static NonTemporary staticMember
;
60 struct MOZ_NON_TEMPORARY_CLASS RandomNonTemporaryClass
{
61 NonTemporary nonstaticMember
;
62 static NonTemporary staticMember
;
65 struct BadInherit
: NonTemporary
{}; // expected-note {{'BadInherit' is a non-temporary type because it inherits from a non-temporary type 'NonTemporary'}}
67 void useStuffWrongly() {
68 gobbleanyref(BadInherit()); // expected-error {{variable of type 'BadInherit' is not valid in a temporary}} expected-note {{value incorrectly allocated in a temporary}}
69 gobbleanyref(RandomClass()); // expected-error {{variable of type 'RandomClass' is not valid in a temporary}} expected-note {{value incorrectly allocated in a temporary}}