Bug 1814798 - pt 1. Add bool to enable/disable PHC at runtime r=glandium
[gecko.git] / build / clang-plugin / tests / TestKungFuDeathGrip.cpp
blob02180158077f2eb49583a3b7a7686f6a95d48ce3
1 #include <utility>
3 #define MOZ_IMPLICIT __attribute__((annotate("moz_implicit")))
5 template <typename T>
6 class already_AddRefed {
7 public:
8 already_AddRefed();
9 T* mPtr;
12 template <typename T>
13 class RefPtr {
14 public:
15 RefPtr();
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.
24 RefPtr(RefPtr<T>&&);
25 RefPtr& operator=(RefPtr<T>&&);
27 void swap(RefPtr<T>& aOther);
29 ~RefPtr();
30 T* mPtr;
33 template <typename T>
34 class nsCOMPtr {
35 public:
36 nsCOMPtr();
37 MOZ_IMPLICIT nsCOMPtr(T* aIn);
38 MOZ_IMPLICIT nsCOMPtr(already_AddRefed<T> aIn);
39 ~nsCOMPtr();
40 T* mPtr;
43 class Type {
44 public:
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;
86 Type *p;
89 struct Type2 {
90 void f() {
91 mWeakRef->f(nullptr, nullptr);
94 void g() {
95 RefPtr<Type> kfdg;
96 kfdg.swap(mStrongRef);
97 f();
100 void h() {
101 RefPtr<Type> kfdg = std::move(mStrongRef);
102 f();
105 RefPtr<Type> mStrongRef;
106 Type* mWeakRef;
109 void f(nsCOMPtr<Type> ignoredArgument, Type *param) {
110 nsCOMPtr<Type> never_referenced;
111 Type t;
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);