Bug 1523562 [wpt PR 14965] - Sync Mozilla CSS tests as of 2019-01-20, a=testonly
[gecko.git] / build / clang-plugin / tests / TestKungFuDeathGrip.cpp
blobc9eef3ff2a5d038ca368072434ef590193af00ff
1 #define MOZ_IMPLICIT __attribute__((annotate("moz_implicit")))
3 template <typename T>
4 class already_AddRefed {
5 public:
6 already_AddRefed();
7 T* mPtr;
8 };
10 template <typename T>
11 class RefPtr {
12 public:
13 RefPtr();
14 MOZ_IMPLICIT RefPtr(T* aIn);
15 MOZ_IMPLICIT RefPtr(already_AddRefed<T> aIn);
16 ~RefPtr();
17 T* mPtr;
20 template <typename T>
21 class nsCOMPtr {
22 public:
23 nsCOMPtr();
24 MOZ_IMPLICIT nsCOMPtr(T* aIn);
25 MOZ_IMPLICIT nsCOMPtr(already_AddRefed<T> aIn);
26 ~nsCOMPtr();
27 T* mPtr;
30 class Type {
31 public:
32 static nsCOMPtr<Type> someStaticCOMPtr;
34 void f(nsCOMPtr<Type> ignoredArgument, Type *param) {
35 nsCOMPtr<Type> never_referenced;
36 nsCOMPtr<Type> kfdg_t1(this);
37 nsCOMPtr<Type> kfdg_t2 = this;
38 nsCOMPtr<Type> kfdg_t3 = (this);
40 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`}}
41 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`}}
42 nsCOMPtr<Type> kfdg_m3(p);
43 kfdg_m3.mPtr->f(nullptr, nullptr);
44 nsCOMPtr<Type> kfdg_m4 = p;
45 kfdg_m4.mPtr->f(nullptr, nullptr);
47 nsCOMPtr<Type> kfdg_a1((already_AddRefed<Type>()));
48 nsCOMPtr<Type> kfdg_a2 = already_AddRefed<Type>();
50 nsCOMPtr<Type> kfdg_p1(param);
51 nsCOMPtr<Type> kfdg_p2 = param;
54 RefPtr<Type> never_referenced2;
55 RefPtr<Type> kfdg_t4(this);
56 RefPtr<Type> kfdg_t5 = this;
57 RefPtr<Type> kfdg_t6 = (this);
59 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`}}
60 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`}}
61 RefPtr<Type> kfdg_m7(p);
62 kfdg_m7.mPtr->f(nullptr, nullptr);
63 RefPtr<Type> kfdg_m8 = p;
64 kfdg_m8.mPtr->f(nullptr, nullptr);
66 RefPtr<Type> kfdg_a3((already_AddRefed<Type>()));
67 RefPtr<Type> kfdg_a4 = already_AddRefed<Type>();
69 RefPtr<Type> kfdg_p3(param);
70 RefPtr<Type> kfdg_p4 = param;
73 Type *p;
76 void f(nsCOMPtr<Type> ignoredArgument, Type *param) {
77 nsCOMPtr<Type> never_referenced;
78 Type t;
79 // Type *p = nullptr;
80 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`}}
81 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`}}
82 nsCOMPtr<Type> kfdg_m3(t.p);
83 kfdg_m3.mPtr->f(nullptr, nullptr);
84 nsCOMPtr<Type> kfdg_m4 = t.p;
85 kfdg_m4.mPtr->f(nullptr, nullptr);
87 nsCOMPtr<Type> kfdg_a1((already_AddRefed<Type>()));
88 nsCOMPtr<Type> kfdg_a2 = already_AddRefed<Type>();
90 nsCOMPtr<Type> kfdg_p1(param);
91 nsCOMPtr<Type> kfdg_p2 = param;
94 RefPtr<Type> never_referenced2;
95 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`}}
96 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`}}
97 RefPtr<Type> kfdg_m7(t.p);
98 kfdg_m7.mPtr->f(nullptr, nullptr);
99 RefPtr<Type> kfdg_m8 = t.p;
100 kfdg_m8.mPtr->f(nullptr, nullptr);
102 RefPtr<Type> kfdg_a3((already_AddRefed<Type>()));
103 RefPtr<Type> kfdg_a4 = already_AddRefed<Type>();
105 RefPtr<Type> kfdg_p3(param);
106 RefPtr<Type> kfdg_p4 = param;
109 nsCOMPtr<Type> Type::someStaticCOMPtr(nullptr);