3 #define MOZ_IMPLICIT __attribute__((annotate("moz_implicit")))
6 class already_AddRefed
{
16 MOZ_IMPLICIT
RefPtr(T
* aIn
);
17 MOZ_IMPLICIT
RefPtr(already_AddRefed
<T
> aIn
);
19 RefPtr(const RefPtr
<T
>& aOther
) = default;
20 RefPtr
& operator=(const RefPtr
<T
>&) = default;
22 // We must define non-defaulted move operations as in the real RefPtr to make
23 // the type non-trivially-copyable.
25 RefPtr
& operator=(RefPtr
<T
>&&);
27 void swap(RefPtr
<T
>& aOther
);
37 MOZ_IMPLICIT
nsCOMPtr(T
* aIn
);
38 MOZ_IMPLICIT
nsCOMPtr(already_AddRefed
<T
> aIn
);
45 static nsCOMPtr
<Type
> someStaticCOMPtr
;
47 void f(nsCOMPtr
<Type
> ignoredArgument
, Type
*param
) {
48 nsCOMPtr
<Type
> never_referenced
;
49 nsCOMPtr
<Type
> kfdg_t1(this);
50 nsCOMPtr
<Type
> kfdg_t2
= this;
51 nsCOMPtr
<Type
> kfdg_t3
= (this);
53 nsCOMPtr
<Type
> kfdg_m1(p
); // expected-error {{Unused "kungFuDeathGrip" 'nsCOMPtr<Type>' objects constructed from members are prohibited}} expected-note {{Please switch all accesses to this member to go through 'kfdg_m1', or explicitly pass 'kfdg_m1' to `mozilla::Unused`}}
54 nsCOMPtr
<Type
> kfdg_m2
= p
; // expected-error {{Unused "kungFuDeathGrip" 'nsCOMPtr<Type>' objects constructed from members are prohibited}} expected-note {{Please switch all accesses to this member to go through 'kfdg_m2', or explicitly pass 'kfdg_m2' to `mozilla::Unused`}}
55 nsCOMPtr
<Type
> kfdg_m3(p
);
56 kfdg_m3
.mPtr
->f(nullptr, nullptr);
57 nsCOMPtr
<Type
> kfdg_m4
= p
;
58 kfdg_m4
.mPtr
->f(nullptr, nullptr);
60 nsCOMPtr
<Type
> kfdg_a1((already_AddRefed
<Type
>()));
61 nsCOMPtr
<Type
> kfdg_a2
= already_AddRefed
<Type
>();
63 nsCOMPtr
<Type
> kfdg_p1(param
);
64 nsCOMPtr
<Type
> kfdg_p2
= param
;
67 RefPtr
<Type
> never_referenced2
;
68 RefPtr
<Type
> kfdg_t4(this);
69 RefPtr
<Type
> kfdg_t5
= this;
70 RefPtr
<Type
> kfdg_t6
= (this);
72 RefPtr
<Type
> kfdg_m5(p
); // expected-error {{Unused "kungFuDeathGrip" 'RefPtr<Type>' objects constructed from members are prohibited}} expected-note {{Please switch all accesses to this member to go through 'kfdg_m5', or explicitly pass 'kfdg_m5' to `mozilla::Unused`}}
73 RefPtr
<Type
> kfdg_m6
= p
; // expected-error {{Unused "kungFuDeathGrip" 'RefPtr<Type>' objects constructed from members are prohibited}} expected-note {{Please switch all accesses to this member to go through 'kfdg_m6', or explicitly pass 'kfdg_m6' to `mozilla::Unused`}}
74 RefPtr
<Type
> kfdg_m7(p
);
75 kfdg_m7
.mPtr
->f(nullptr, nullptr);
76 RefPtr
<Type
> kfdg_m8
= p
;
77 kfdg_m8
.mPtr
->f(nullptr, nullptr);
79 RefPtr
<Type
> kfdg_a3((already_AddRefed
<Type
>()));
80 RefPtr
<Type
> kfdg_a4
= already_AddRefed
<Type
>();
82 RefPtr
<Type
> kfdg_p3(param
);
83 RefPtr
<Type
> kfdg_p4
= param
;
91 mWeakRef
->f(nullptr, nullptr);
96 kfdg
.swap(mStrongRef
);
101 RefPtr
<Type
> kfdg
= std::move(mStrongRef
);
105 RefPtr
<Type
> mStrongRef
;
109 void f(nsCOMPtr
<Type
> ignoredArgument
, Type
*param
) {
110 nsCOMPtr
<Type
> never_referenced
;
112 // Type *p = nullptr;
113 nsCOMPtr
<Type
> kfdg_m1(t
.p
); // expected-error {{Unused "kungFuDeathGrip" 'nsCOMPtr<Type>' objects constructed from members are prohibited}} expected-note {{Please switch all accesses to this member to go through 'kfdg_m1', or explicitly pass 'kfdg_m1' to `mozilla::Unused`}}
114 nsCOMPtr
<Type
> kfdg_m2
= t
.p
; // expected-error {{Unused "kungFuDeathGrip" 'nsCOMPtr<Type>' objects constructed from members are prohibited}} expected-note {{Please switch all accesses to this member to go through 'kfdg_m2', or explicitly pass 'kfdg_m2' to `mozilla::Unused`}}
115 nsCOMPtr
<Type
> kfdg_m3(t
.p
);
116 kfdg_m3
.mPtr
->f(nullptr, nullptr);
117 nsCOMPtr
<Type
> kfdg_m4
= t
.p
;
118 kfdg_m4
.mPtr
->f(nullptr, nullptr);
120 nsCOMPtr
<Type
> kfdg_a1((already_AddRefed
<Type
>()));
121 nsCOMPtr
<Type
> kfdg_a2
= already_AddRefed
<Type
>();
123 nsCOMPtr
<Type
> kfdg_p1(param
);
124 nsCOMPtr
<Type
> kfdg_p2
= param
;
127 RefPtr
<Type
> never_referenced2
;
128 RefPtr
<Type
> kfdg_m5(t
.p
); // expected-error {{Unused "kungFuDeathGrip" 'RefPtr<Type>' objects constructed from members are prohibited}} expected-note {{Please switch all accesses to this member to go through 'kfdg_m5', or explicitly pass 'kfdg_m5' to `mozilla::Unused`}}
129 RefPtr
<Type
> kfdg_m6
= t
.p
; // expected-error {{Unused "kungFuDeathGrip" 'RefPtr<Type>' objects constructed from members are prohibited}} expected-note {{Please switch all accesses to this member to go through 'kfdg_m6', or explicitly pass 'kfdg_m6' to `mozilla::Unused`}}
130 RefPtr
<Type
> kfdg_m7(t
.p
);
131 kfdg_m7
.mPtr
->f(nullptr, nullptr);
132 RefPtr
<Type
> kfdg_m8
= t
.p
;
133 kfdg_m8
.mPtr
->f(nullptr, nullptr);
135 RefPtr
<Type
> kfdg_a3((already_AddRefed
<Type
>()));
136 RefPtr
<Type
> kfdg_a4
= already_AddRefed
<Type
>();
138 RefPtr
<Type
> kfdg_p3(param
);
139 RefPtr
<Type
> kfdg_p4
= param
;
142 nsCOMPtr
<Type
> Type::someStaticCOMPtr(nullptr);