Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(498)

Side by Side Diff: base/bind_unittest.nc

Issue 12040055: Fix no-compile tests in base. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | base/memory/scoped_ptr_unittest.nc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/callback.h" 5 #include "base/callback.h"
6 #include "base/bind.h" 6 #include "base/bind.h"
7 #include "base/memory/ref_counted.h" 7 #include "base/memory/ref_counted.h"
8 8
9 namespace base { 9 namespace base {
10 10
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
136 // First, non-const reference parameters are disallowed by the Google 136 // First, non-const reference parameters are disallowed by the Google
137 // style guide. Second, since we are doing argument forwarding it becomes 137 // style guide. Second, since we are doing argument forwarding it becomes
138 // very tricky to avoid copies, maintain const correctness, and not 138 // very tricky to avoid copies, maintain const correctness, and not
139 // accidentally have the function be modifying a temporary, or a copy. 139 // accidentally have the function be modifying a temporary, or a copy.
140 void WontCompile() { 140 void WontCompile() {
141 Parent p; 141 Parent p;
142 Callback<int(Parent&)> ref_arg_cb = Bind(&UnwrapParentRef); 142 Callback<int(Parent&)> ref_arg_cb = Bind(&UnwrapParentRef);
143 ref_arg_cb.Run(p); 143 ref_arg_cb.Run(p);
144 } 144 }
145 145
146 #elif defined(NCTEST_DISALLOW_BIND_TO_NON_CONST_REF_PARAM) // [r"creating array with negative size"] 146 #elif defined(NCTEST_DISALLOW_BIND_TO_NON_CONST_REF_PARAM) // [r"size of array is negative"]
147 147
148 // Binding functions with reference parameters, unsupported. 148 // Binding functions with reference parameters, unsupported.
149 // 149 //
150 // See comment in NCTEST_DISALLOW_NON_CONST_REF_PARAM 150 // See comment in NCTEST_DISALLOW_NON_CONST_REF_PARAM
151 void WontCompile() { 151 void WontCompile() {
152 Parent p; 152 Parent p;
153 Callback<int(void)> ref_cb = Bind(&UnwrapParentRef, p); 153 Callback<int(void)> ref_cb = Bind(&UnwrapParentRef, p);
154 ref_cb.Run(); 154 ref_cb.Run();
155 } 155 }
156 156
157 #elif defined(NCTEST_NO_IMPLICIT_ARRAY_PTR_CONVERSION) // [r"creating array wit h negative size"] 157 #elif defined(NCTEST_NO_IMPLICIT_ARRAY_PTR_CONVERSION) // [r"size of array is n egative"]
158 158
159 // A method should not be bindable with an array of objects. 159 // A method should not be bindable with an array of objects.
160 // 160 //
161 // This is likely not wanted behavior. We specifically check for it though 161 // This is likely not wanted behavior. We specifically check for it though
162 // because it is possible, depending on how you implement prebinding, to 162 // because it is possible, depending on how you implement prebinding, to
163 // implicitly convert an array type to a pointer type. 163 // implicitly convert an array type to a pointer type.
164 void WontCompile() { 164 void WontCompile() {
165 HasRef p[10]; 165 HasRef p[10];
166 Callback<void(void)> method_bound_to_array_cb = 166 Callback<void(void)> method_bound_to_array_cb =
167 Bind(&HasRef::VoidMethod0, p); 167 Bind(&HasRef::VoidMethod0, p);
168 method_bound_to_array_cb.Run(); 168 method_bound_to_array_cb.Run();
169 } 169 }
170 170
171 #elif defined(NCTEST_NO_RAW_PTR_FOR_REFCOUNTED_TYPES) // [r"creating array with negative size"] 171 #elif defined(NCTEST_NO_RAW_PTR_FOR_REFCOUNTED_TYPES) // [r"size of array is ne gative"]
172 172
173 // Refcounted types should not be bound as a raw pointer. 173 // Refcounted types should not be bound as a raw pointer.
174 void WontCompile() { 174 void WontCompile() {
175 HasRef for_raw_ptr; 175 HasRef for_raw_ptr;
176 int a; 176 int a;
177 Callback<void(void)> ref_count_as_raw_ptr_a = 177 Callback<void(void)> ref_count_as_raw_ptr_a =
178 Bind(&VoidPolymorphic1<int*>, &a); 178 Bind(&VoidPolymorphic1<int*>, &a);
179 Callback<void(void)> ref_count_as_raw_ptr = 179 Callback<void(void)> ref_count_as_raw_ptr =
180 Bind(&VoidPolymorphic1<HasRef*>, &for_raw_ptr); 180 Bind(&VoidPolymorphic1<HasRef*>, &for_raw_ptr);
181 } 181 }
182 182
183 #elif defined(NCTEST_WEAKPTR_BIND_MUST_RETURN_VOID) // [r"creating array with n egative size"] 183 #elif defined(NCTEST_WEAKPTR_BIND_MUST_RETURN_VOID) // [r"size of array is nega tive"]
184 184
185 // WeakPtrs cannot be bound to methods with return types. 185 // WeakPtrs cannot be bound to methods with return types.
186 void WontCompile() { 186 void WontCompile() {
187 NoRef no_ref; 187 NoRef no_ref;
188 WeakPtrFactory<NoRef> weak_factory(&no_ref); 188 WeakPtrFactory<NoRef> weak_factory(&no_ref);
189 Callback<int(void)> weak_ptr_with_non_void_return_type = 189 Callback<int(void)> weak_ptr_with_non_void_return_type =
190 Bind(&NoRef::IntMethod0, weak_factory.GetWeakPtr()); 190 Bind(&NoRef::IntMethod0, weak_factory.GetWeakPtr());
191 weak_ptr_with_non_void_return_type.Run(); 191 weak_ptr_with_non_void_return_type.Run();
192 } 192 }
193 193
194 #elif defined(NCTEST_DISALLOW_ASSIGN_DIFFERINT_TYPES) // [r"invalid conversion from"] 194 #elif defined(NCTEST_DISALLOW_ASSIGN_DIFFERENT_TYPES) // [r"conversion from 'ba se::Callback<void\(int\)>' to non-scalar type"]
195 195
196 // Bind result cannot be assigned to Callbacks with a mismatching type. 196 // Bind result cannot be assigned to Callbacks with a mismatching type.
197 void WontCompile() { 197 void WontCompile() {
198 Closure callback_mismatches_bind_type = Bind(&VoidPolymorphic1<int>); 198 Closure callback_mismatches_bind_type = Bind(&VoidPolymorphic1<int>);
199 } 199 }
200 200
201 #endif 201 #endif
202 202
203 } // namespace base 203 } // namespace base
OLDNEW
« no previous file with comments | « no previous file | base/memory/scoped_ptr_unittest.nc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698