OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "base/memory/weak_ptr.h" | 5 #include "base/memory/weak_ptr.h" |
6 | 6 |
7 namespace base { | 7 namespace base { |
8 | 8 |
9 struct Producer : SupportsWeakPtr<Producer> {}; | 9 struct Producer : SupportsWeakPtr<Producer> {}; |
10 struct DerivedProducer : Producer {}; | 10 struct DerivedProducer : Producer {}; |
11 struct OtherDerivedProducer : Producer {}; | 11 struct OtherDerivedProducer : Producer {}; |
12 struct MultiplyDerivedProducer : Producer, | 12 struct MultiplyDerivedProducer : Producer, |
13 SupportsWeakPtr<MultiplyDerivedProducer> {}; | 13 SupportsWeakPtr<MultiplyDerivedProducer> {}; |
14 struct Unrelated {}; | 14 struct Unrelated {}; |
15 struct DerivedUnrelated : Unrelated {}; | 15 struct DerivedUnrelated : Unrelated {}; |
16 | 16 |
17 #if defined(NCTEST_AUTO_DOWNCAST) // [r"invalid conversion from"] | 17 #if defined(NCTEST_AUTO_DOWNCAST) // [r"fatal error: cannot initialize a member
subobject of type 'base::DerivedProducer \*' with an lvalue of type 'base::Prod
ucer \*const'"] |
18 | 18 |
19 void WontCompile() { | 19 void WontCompile() { |
20 Producer f; | 20 Producer f; |
21 WeakPtr<Producer> ptr = f.AsWeakPtr(); | 21 WeakPtr<Producer> ptr = f.AsWeakPtr(); |
22 WeakPtr<DerivedProducer> derived_ptr = ptr; | 22 WeakPtr<DerivedProducer> derived_ptr = ptr; |
23 } | 23 } |
24 | 24 |
25 #elif defined(NCTEST_STATIC_DOWNCAST) // [r"invalid conversion from"] | 25 #elif defined(NCTEST_STATIC_DOWNCAST) // [r"fatal error: cannot initialize a me
mber subobject of type 'base::DerivedProducer \*' with an lvalue of type 'base::
Producer \*const'"] |
26 | 26 |
27 void WontCompile() { | 27 void WontCompile() { |
28 Producer f; | 28 Producer f; |
29 WeakPtr<Producer> ptr = f.AsWeakPtr(); | 29 WeakPtr<Producer> ptr = f.AsWeakPtr(); |
30 WeakPtr<DerivedProducer> derived_ptr = | 30 WeakPtr<DerivedProducer> derived_ptr = |
31 static_cast<WeakPtr<DerivedProducer> >(ptr); | 31 static_cast<WeakPtr<DerivedProducer> >(ptr); |
32 } | 32 } |
33 | 33 |
34 #elif defined(NCTEST_AUTO_REF_DOWNCAST) // [r"invalid initialization of referen
ce"] | 34 #elif defined(NCTEST_AUTO_REF_DOWNCAST) // [r"fatal error: non-const lvalue ref
erence to type 'WeakPtr<base::DerivedProducer>' cannot bind to a value of unrela
ted type 'WeakPtr<base::Producer>'"] |
35 | 35 |
36 void WontCompile() { | 36 void WontCompile() { |
37 Producer f; | 37 Producer f; |
38 WeakPtr<Producer> ptr = f.AsWeakPtr(); | 38 WeakPtr<Producer> ptr = f.AsWeakPtr(); |
39 WeakPtr<DerivedProducer>& derived_ptr = ptr; | 39 WeakPtr<DerivedProducer>& derived_ptr = ptr; |
40 } | 40 } |
41 | 41 |
42 #elif defined(NCTEST_STATIC_REF_DOWNCAST) // [r"invalid static_cast"] | 42 #elif defined(NCTEST_STATIC_REF_DOWNCAST) // [r"fatal error: non-const lvalue r
eference to type 'WeakPtr<base::DerivedProducer>' cannot bind to a value of unre
lated type 'WeakPtr<base::Producer>'"] |
43 | 43 |
44 void WontCompile() { | 44 void WontCompile() { |
45 Producer f; | 45 Producer f; |
46 WeakPtr<Producer> ptr = f.AsWeakPtr(); | 46 WeakPtr<Producer> ptr = f.AsWeakPtr(); |
47 WeakPtr<DerivedProducer>& derived_ptr = | 47 WeakPtr<DerivedProducer>& derived_ptr = |
48 static_cast<WeakPtr<DerivedProducer>&>(ptr); | 48 static_cast<WeakPtr<DerivedProducer>&>(ptr); |
49 } | 49 } |
50 | 50 |
51 #elif defined(NCTEST_STATIC_ASWEAKPTR_DOWNCAST) // [r"no matching function"] | 51 #elif defined(NCTEST_STATIC_ASWEAKPTR_DOWNCAST) // [r"no matching function"] |
52 | 52 |
53 void WontCompile() { | 53 void WontCompile() { |
54 Producer f; | 54 Producer f; |
55 WeakPtr<DerivedProducer> ptr = | 55 WeakPtr<DerivedProducer> ptr = |
56 SupportsWeakPtr<Producer>::StaticAsWeakPtr<DerivedProducer>(&f); | 56 SupportsWeakPtr<Producer>::StaticAsWeakPtr<DerivedProducer>(&f); |
57 } | 57 } |
58 | 58 |
59 #elif defined(NCTEST_UNSAFE_HELPER_DOWNCAST) // [r"invalid conversion from"] | 59 #elif defined(NCTEST_UNSAFE_HELPER_DOWNCAST) // [r"fatal error: cannot initiali
ze a member subobject of type 'base::DerivedProducer \*' with an lvalue of type
'base::Producer \*const'"] |
60 | 60 |
61 void WontCompile() { | 61 void WontCompile() { |
62 Producer f; | 62 Producer f; |
63 WeakPtr<DerivedProducer> ptr = AsWeakPtr(&f); | 63 WeakPtr<DerivedProducer> ptr = AsWeakPtr(&f); |
64 } | 64 } |
65 | 65 |
66 #elif defined(NCTEST_UNSAFE_INSTANTIATED_HELPER_DOWNCAST) // [r"no matching fun
ction"] | 66 #elif defined(NCTEST_UNSAFE_INSTANTIATED_HELPER_DOWNCAST) // [r"no matching fun
ction"] |
67 | 67 |
68 void WontCompile() { | 68 void WontCompile() { |
69 Producer f; | 69 Producer f; |
70 WeakPtr<DerivedProducer> ptr = AsWeakPtr<DerivedProducer>(&f); | 70 WeakPtr<DerivedProducer> ptr = AsWeakPtr<DerivedProducer>(&f); |
71 } | 71 } |
72 | 72 |
73 #elif defined(NCTEST_UNSAFE_WRONG_INSANTIATED_HELPER_DOWNCAST) // [r"invalid co
nversion from"] | 73 #elif defined(NCTEST_UNSAFE_WRONG_INSANTIATED_HELPER_DOWNCAST) // [r"fatal erro
r: cannot initialize a member subobject of type 'base::DerivedProducer \*' with
an lvalue of type 'base::Producer \*const'"] |
74 | 74 |
75 void WontCompile() { | 75 void WontCompile() { |
76 Producer f; | 76 Producer f; |
77 WeakPtr<DerivedProducer> ptr = AsWeakPtr<Producer>(&f); | 77 WeakPtr<DerivedProducer> ptr = AsWeakPtr<Producer>(&f); |
78 } | 78 } |
79 | 79 |
80 #elif defined(NCTEST_UNSAFE_HELPER_CAST) // [r"cannot convert"] | 80 #elif defined(NCTEST_UNSAFE_HELPER_CAST) // [r"fatal error: cannot initialize a
member subobject of type 'base::OtherDerivedProducer \*' with an lvalue of type
'base::DerivedProducer \*const'"] |
81 | 81 |
82 void WontCompile() { | 82 void WontCompile() { |
83 DerivedProducer f; | 83 DerivedProducer f; |
84 WeakPtr<OtherDerivedProducer> ptr = AsWeakPtr(&f); | 84 WeakPtr<OtherDerivedProducer> ptr = AsWeakPtr(&f); |
85 } | 85 } |
86 | 86 |
87 #elif defined(NCTEST_UNSAFE_INSTANTIATED_HELPER_SIDECAST) // [r"no matching fun
ction"] | 87 #elif defined(NCTEST_UNSAFE_INSTANTIATED_HELPER_SIDECAST) // [r"fatal error: no
matching function for call to 'AsWeakPtr'"] |
88 | 88 |
89 void WontCompile() { | 89 void WontCompile() { |
90 DerivedProducer f; | 90 DerivedProducer f; |
91 WeakPtr<OtherDerivedProducer> ptr = AsWeakPtr<OtherDerivedProducer>(&f); | 91 WeakPtr<OtherDerivedProducer> ptr = AsWeakPtr<OtherDerivedProducer>(&f); |
92 } | 92 } |
93 | 93 |
94 #elif defined(NCTEST_UNSAFE_WRONG_INSTANTIATED_HELPER_SIDECAST) // [r"cannot co
nvert"] | 94 #elif defined(NCTEST_UNSAFE_WRONG_INSTANTIATED_HELPER_SIDECAST) // [r"fatal err
or: cannot initialize a member subobject of type 'base::OtherDerivedProducer \*'
with an lvalue of type 'base::DerivedProducer \*const'"] |
95 | 95 |
96 void WontCompile() { | 96 void WontCompile() { |
97 DerivedProducer f; | 97 DerivedProducer f; |
98 WeakPtr<OtherDerivedProducer> ptr = AsWeakPtr<DerivedProducer>(&f); | 98 WeakPtr<OtherDerivedProducer> ptr = AsWeakPtr<DerivedProducer>(&f); |
99 } | 99 } |
100 | 100 |
101 #elif defined(NCTEST_UNRELATED_HELPER) // [r"cannot convert"] | 101 #elif defined(NCTEST_UNRELATED_HELPER) // [r"fatal error: cannot initialize a m
ember subobject of type 'base::Unrelated \*' with an lvalue of type 'base::Deriv
edProducer \*const'"] |
102 | 102 |
103 void WontCompile() { | 103 void WontCompile() { |
104 DerivedProducer f; | 104 DerivedProducer f; |
105 WeakPtr<Unrelated> ptr = AsWeakPtr(&f); | 105 WeakPtr<Unrelated> ptr = AsWeakPtr(&f); |
106 } | 106 } |
107 | 107 |
108 #elif defined(NCTEST_UNRELATED_INSTANTIATED_HELPER) // [r"no matching function"
] | 108 #elif defined(NCTEST_UNRELATED_INSTANTIATED_HELPER) // [r"no matching function"
] |
109 | 109 |
110 void WontCompile() { | 110 void WontCompile() { |
111 DerivedProducer f; | 111 DerivedProducer f; |
112 WeakPtr<Unrelated> ptr = AsWeakPtr<Unrelated>(&f); | 112 WeakPtr<Unrelated> ptr = AsWeakPtr<Unrelated>(&f); |
113 } | 113 } |
114 | 114 |
115 #elif defined(NCTEST_COMPLETELY_UNRELATED_HELPER) // [r"size of array is negati
ve"] | 115 #elif defined(NCTEST_COMPLETELY_UNRELATED_HELPER) // [r"fatal error: static_ass
ert failed \"AsWeakPtr_argument_inherits_from_SupportsWeakPtr\""] |
116 | 116 |
117 void WontCompile() { | 117 void WontCompile() { |
118 Unrelated f; | 118 Unrelated f; |
119 WeakPtr<Unrelated> ptr = AsWeakPtr(&f); | 119 WeakPtr<Unrelated> ptr = AsWeakPtr(&f); |
120 } | 120 } |
121 | 121 |
122 #elif defined(NCTEST_DERIVED_COMPLETELY_UNRELATED_HELPER) // [r"size of array i
s negative"] | 122 #elif defined(NCTEST_DERIVED_COMPLETELY_UNRELATED_HELPER) // [r"fatal error: st
atic_assert failed \"AsWeakPtr_argument_inherits_from_SupportsWeakPtr\""] |
123 | 123 |
124 void WontCompile() { | 124 void WontCompile() { |
125 DerivedUnrelated f; | 125 DerivedUnrelated f; |
126 WeakPtr<Unrelated> ptr = AsWeakPtr(&f); | 126 WeakPtr<Unrelated> ptr = AsWeakPtr(&f); |
127 } | 127 } |
128 | 128 |
129 #elif defined(NCTEST_AMBIGUOUS_ANCESTORS) // [r"ambiguous base"] | 129 #elif defined(NCTEST_AMBIGUOUS_ANCESTORS) // [r"fatal error: ambiguous conversi
on from derived class 'base::MultiplyDerivedProducer' to base class 'base::inter
nal::SupportsWeakPtrBase':"] |
130 | 130 |
131 void WontCompile() { | 131 void WontCompile() { |
132 MultiplyDerivedProducer f; | 132 MultiplyDerivedProducer f; |
133 WeakPtr<MultiplyDerivedProducer> ptr = AsWeakPtr(&f); | 133 WeakPtr<MultiplyDerivedProducer> ptr = AsWeakPtr(&f); |
134 } | 134 } |
135 | 135 |
136 #endif | 136 #endif |
137 | 137 |
138 } | 138 } |
OLD | NEW |