Bug 1523562 [wpt PR 14965] - Sync Mozilla CSS tests as of 2019-01-20, a=testonly
[gecko.git] / build / clang-plugin / tests / TestNoAddRefReleaseOnReturn.cpp
blob2e1f83377e50374b46a82d71dd9f16c1f5c4cea7
1 #define MOZ_NO_ADDREF_RELEASE_ON_RETURN __attribute__((annotate("moz_no_addref_release_on_return")))
3 struct Test {
4 void AddRef();
5 void Release();
6 void foo();
7 };
9 struct TestD : Test {};
11 struct S {
12 Test* f() MOZ_NO_ADDREF_RELEASE_ON_RETURN;
13 Test& g() MOZ_NO_ADDREF_RELEASE_ON_RETURN;
14 Test h() MOZ_NO_ADDREF_RELEASE_ON_RETURN;
17 struct SD {
18 TestD* f() MOZ_NO_ADDREF_RELEASE_ON_RETURN;
19 TestD& g() MOZ_NO_ADDREF_RELEASE_ON_RETURN;
20 TestD h() MOZ_NO_ADDREF_RELEASE_ON_RETURN;
23 template<class T>
24 struct X {
25 T* f() MOZ_NO_ADDREF_RELEASE_ON_RETURN;
26 T& g() MOZ_NO_ADDREF_RELEASE_ON_RETURN;
27 T h() MOZ_NO_ADDREF_RELEASE_ON_RETURN;
30 template<class T>
31 struct SP {
32 T* operator->() MOZ_NO_ADDREF_RELEASE_ON_RETURN;
35 Test* f() MOZ_NO_ADDREF_RELEASE_ON_RETURN;
36 Test& g() MOZ_NO_ADDREF_RELEASE_ON_RETURN;
37 Test h() MOZ_NO_ADDREF_RELEASE_ON_RETURN;
39 TestD* fd() MOZ_NO_ADDREF_RELEASE_ON_RETURN;
40 TestD& gd() MOZ_NO_ADDREF_RELEASE_ON_RETURN;
41 TestD hd() MOZ_NO_ADDREF_RELEASE_ON_RETURN;
43 void test() {
44 S s;
45 s.f()->AddRef(); // expected-error{{'AddRef' cannot be called on the return value of 'f'}}
46 s.f()->Release(); // expected-error{{'Release' cannot be called on the return value of 'f'}}
47 s.f()->foo();
48 s.g().AddRef(); // expected-error{{'AddRef' cannot be called on the return value of 'g'}}
49 s.g().Release(); // expected-error{{'Release' cannot be called on the return value of 'g'}}
50 s.g().foo();
51 s.h().AddRef(); // expected-error{{'AddRef' cannot be called on the return value of 'h'}}
52 s.h().Release(); // expected-error{{'Release' cannot be called on the return value of 'h'}}
53 s.h().foo();
54 SD sd;
55 sd.f()->AddRef(); // expected-error{{'AddRef' cannot be called on the return value of 'f'}}
56 sd.f()->Release(); // expected-error{{'Release' cannot be called on the return value of 'f'}}
57 sd.f()->foo();
58 sd.g().AddRef(); // expected-error{{'AddRef' cannot be called on the return value of 'g'}}
59 sd.g().Release(); // expected-error{{'Release' cannot be called on the return value of 'g'}}
60 sd.g().foo();
61 sd.h().AddRef(); // expected-error{{'AddRef' cannot be called on the return value of 'h'}}
62 sd.h().Release(); // expected-error{{'Release' cannot be called on the return value of 'h'}}
63 sd.h().foo();
64 X<Test> x;
65 x.f()->AddRef(); // expected-error{{'AddRef' cannot be called on the return value of 'f'}}
66 x.f()->Release(); // expected-error{{'Release' cannot be called on the return value of 'f'}}
67 x.f()->foo();
68 x.g().AddRef(); // expected-error{{'AddRef' cannot be called on the return value of 'g'}}
69 x.g().Release(); // expected-error{{'Release' cannot be called on the return value of 'g'}}
70 x.g().foo();
71 x.h().AddRef(); // expected-error{{'AddRef' cannot be called on the return value of 'h'}}
72 x.h().Release(); // expected-error{{'Release' cannot be called on the return value of 'h'}}
73 x.h().foo();
74 X<TestD> xd;
75 xd.f()->AddRef(); // expected-error{{'AddRef' cannot be called on the return value of 'f'}}
76 xd.f()->Release(); // expected-error{{'Release' cannot be called on the return value of 'f'}}
77 xd.f()->foo();
78 xd.g().AddRef(); // expected-error{{'AddRef' cannot be called on the return value of 'g'}}
79 xd.g().Release(); // expected-error{{'Release' cannot be called on the return value of 'g'}}
80 xd.g().foo();
81 xd.h().AddRef(); // expected-error{{'AddRef' cannot be called on the return value of 'h'}}
82 xd.h().Release(); // expected-error{{'Release' cannot be called on the return value of 'h'}}
83 xd.h().foo();
84 SP<Test> sp;
85 sp->AddRef(); // expected-error{{'AddRef' cannot be called on the return value of 'operator->'}}
86 sp->Release(); // expected-error{{'Release' cannot be called on the return value of 'operator->'}}
87 sp->foo();
88 SP<TestD> spd;
89 spd->AddRef(); // expected-error{{'AddRef' cannot be called on the return value of 'operator->'}}
90 spd->Release(); // expected-error{{'Release' cannot be called on the return value of 'operator->'}}
91 spd->foo();
92 f()->AddRef(); // expected-error{{'AddRef' cannot be called on the return value of 'f'}}
93 f()->Release(); // expected-error{{'Release' cannot be called on the return value of 'f'}}
94 f()->foo();
95 g().AddRef(); // expected-error{{'AddRef' cannot be called on the return value of 'g'}}
96 g().Release(); // expected-error{{'Release' cannot be called on the return value of 'g'}}
97 g().foo();
98 h().AddRef(); // expected-error{{'AddRef' cannot be called on the return value of 'h'}}
99 h().Release(); // expected-error{{'Release' cannot be called on the return value of 'h'}}
100 h().foo();
101 fd()->AddRef(); // expected-error{{'AddRef' cannot be called on the return value of 'fd'}}
102 fd()->Release(); // expected-error{{'Release' cannot be called on the return value of 'fd'}}
103 fd()->foo();
104 gd().AddRef(); // expected-error{{'AddRef' cannot be called on the return value of 'gd'}}
105 gd().Release(); // expected-error{{'Release' cannot be called on the return value of 'gd'}}
106 gd().foo();
107 hd().AddRef(); // expected-error{{'AddRef' cannot be called on the return value of 'hd'}}
108 hd().Release(); // expected-error{{'Release' cannot be called on the return value of 'hd'}}
109 hd().foo();