OLD | NEW |
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 | 6 |
7 namespace base { | 7 namespace base { |
8 | 8 |
9 class Parent { | 9 class Parent { |
10 }; | 10 }; |
11 | 11 |
12 class Child : Parent { | 12 class Child : Parent { |
13 }; | 13 }; |
14 | 14 |
15 #if defined(NCTEST_EQUALS_REQUIRES_SAMETYPE) // [r"no matching function for cal
l to 'base::Callback<void\(\)>::Equals\(base::Callback<int\(\)>&\)'"] | 15 #if defined(NCTEST_EQUALS_REQUIRES_SAMETYPE) // [r"fatal error: no viable conve
rsion from 'Callback<int \(\)>' to 'const Callback<void \(\)>'"] |
16 | 16 |
17 // Attempting to call comparison function on two callbacks of different type. | 17 // Attempting to call comparison function on two callbacks of different type. |
18 // | 18 // |
19 // This should be a compile time failure because each callback type should be | 19 // This should be a compile time failure because each callback type should be |
20 // considered distinct. | 20 // considered distinct. |
21 void WontCompile() { | 21 void WontCompile() { |
22 Closure c1; | 22 Closure c1; |
23 Callback<int(void)> c2; | 23 Callback<int(void)> c2; |
24 c1.Equals(c2); | 24 c1.Equals(c2); |
25 } | 25 } |
26 | 26 |
27 #elif defined(NCTEST_CONSTRUCTION_FROM_SUBTYPE) // [r"conversion from 'base::Ca
llback<base::Parent\(\)>' to non-scalar type 'base::Callback<base::Child\(\)>'"] | 27 #elif defined(NCTEST_CONSTRUCTION_FROM_SUBTYPE) // [r"fatal error: no viable co
nversion from 'Callback<base::Parent \(\)>' to 'Callback<base::Child \(\)>'"] |
28 | 28 |
29 // Construction of Callback<A> from Callback<B> if A is supertype of B. | 29 // Construction of Callback<A> from Callback<B> if A is supertype of B. |
30 // | 30 // |
31 // While this is technically safe, most people aren't used to it when coding | 31 // While this is technically safe, most people aren't used to it when coding |
32 // C++ so if this is happening, it is almost certainly an error. | 32 // C++ so if this is happening, it is almost certainly an error. |
33 void WontCompile() { | 33 void WontCompile() { |
34 Callback<Parent(void)> cb_a; | 34 Callback<Parent(void)> cb_a; |
35 Callback<Child(void)> cb_b = cb_a; | 35 Callback<Child(void)> cb_b = cb_a; |
36 } | 36 } |
37 | 37 |
38 #elif defined(NCTEST_ASSIGNMENT_FROM_SUBTYPE) // [r"no match for 'operator=' in
'cb_a = cb_b'"] | 38 #elif defined(NCTEST_ASSIGNMENT_FROM_SUBTYPE) // [r"fatal error: no viable over
loaded '='"] |
39 | 39 |
40 // Assignment of Callback<A> from Callback<B> if A is supertype of B. | 40 // Assignment of Callback<A> from Callback<B> if A is supertype of B. |
41 // See explanation for NCTEST_CONSTRUCTION_FROM_SUBTYPE | 41 // See explanation for NCTEST_CONSTRUCTION_FROM_SUBTYPE |
42 void WontCompile() { | 42 void WontCompile() { |
43 Callback<Parent(void)> cb_a; | 43 Callback<Parent(void)> cb_a; |
44 Callback<Child(void)> cb_b; | 44 Callback<Child(void)> cb_b; |
45 cb_a = cb_b; | 45 cb_a = cb_b; |
46 } | 46 } |
47 | 47 |
48 #endif | 48 #endif |
49 | 49 |
50 } // namespace base | 50 } // namespace base |
OLD | NEW |