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

Side by Side Diff: base/bind_unittest.nc

Issue 7780016: Make Callback.Equals() only work when comparing against the same type. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 years, 3 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 | « base/base.gyp ('k') | base/callback.h » ('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 7
8 namespace base { 8 namespace base {
9 9
10 // Do not put everything inside an anonymous namespace. If you do, many of the 10 // Do not put everything inside an anonymous namespace. If you do, many of the
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
72 // Method bound to const-object. 72 // Method bound to const-object.
73 // 73 //
74 // Only const methods should be allowed to work with const objects. 74 // Only const methods should be allowed to work with const objects.
75 void WontCompile() { 75 void WontCompile() {
76 HasRef has_ref; 76 HasRef has_ref;
77 const HasRef* const_has_ref_ptr_ = &has_ref; 77 const HasRef* const_has_ref_ptr_ = &has_ref;
78 Callback<void(void)> method_to_const_cb = 78 Callback<void(void)> method_to_const_cb =
79 Bind(&HasRef::VoidMethod0, const_has_ref_ptr_); 79 Bind(&HasRef::VoidMethod0, const_has_ref_ptr_);
80 method_to_const_cb.Run(); 80 method_to_const_cb.Run();
81 } 81 }
82 82
willchan no longer on Chromium 2011/09/10 00:40:59 Why are these getting deleted?
awong 2011/09/10 00:57:45 I just moved them. They're in callback_unittest.nc
83 #elif defined(NCTEST_CONSTRUCTION_FROM_SUBTYPE) // [r"conversion from 'base::Ca llback<int\(\)>' to non-scalar type 'base::Callback<void\(\)>'"]
84
85 // Construction of Callback<A> from Callback<B> if A is supertype of B.
86 //
87 // While this is technically safe, most people aren't used to it when coding
88 // C++ so if this is happening, it is almost certainly an error.
89 void WontCompile() {
90 Callback<int(void)> cb_a = Bind(&PolymorphicIdentity<int>, 1);
91 Callback<void(void)> cb_b = cb_a;
92 }
93
94 #elif defined(NCTEST_ASSIGNMENT_FROM_SUBTYPE) // [r"no match for 'operator=' in 'cb_a = cb_b'"]
95
96 // Assignment of Callback<A> from Callback<B> if A is supertype of B.
97 // See explanation for NCTEST_CONSTRUCTION_FROM_SUBTYPE
98 void WontCompile() {
99 Callback<int(void)> cb_a = Bind(&PolymorphicIdentity<int>, 1);
100 Callback<void(void)> cb_b;
101 cb_a = cb_b;
102 }
103
104 #elif defined(NCTEST_METHOD_BIND_NEEDS_REFCOUNTED_OBJECT) // [r"has no member n amed 'AddRef'"] 83 #elif defined(NCTEST_METHOD_BIND_NEEDS_REFCOUNTED_OBJECT) // [r"has no member n amed 'AddRef'"]
105 84
106 // Method bound to non-refcounted object. 85 // Method bound to non-refcounted object.
107 // 86 //
108 // We require refcounts unless you have Unretained(). 87 // We require refcounts unless you have Unretained().
109 void WontCompile() { 88 void WontCompile() {
110 NoRef no_ref; 89 NoRef no_ref;
111 Callback<void(void)> no_ref_cb = 90 Callback<void(void)> no_ref_cb =
112 Bind(&NoRef::VoidMethod0, &no_ref); 91 Bind(&NoRef::VoidMethod0, &no_ref);
113 no_ref_cb.Run(); 92 no_ref_cb.Run();
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
214 #elif defined(NCTEST_DISALLOW_ASSIGN_DIFFERINT_TYPES) // [r"creating array with negative size"] 193 #elif defined(NCTEST_DISALLOW_ASSIGN_DIFFERINT_TYPES) // [r"creating array with negative size"]
215 194
216 // Bind result cannot be assigned to Callbacks with a mismatching type. 195 // Bind result cannot be assigned to Callbacks with a mismatching type.
217 void WontCompile() { 196 void WontCompile() {
218 Closure callback_mismatches_bind_type = Bind(&VoidPolymorphic1<int>); 197 Closure callback_mismatches_bind_type = Bind(&VoidPolymorphic1<int>);
219 } 198 }
220 199
221 #endif 200 #endif
222 201
223 } // namespace base 202 } // namespace base
OLDNEW
« no previous file with comments | « base/base.gyp ('k') | base/callback.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698