[email protected] | 481915a77 | 2011-09-10 03:14:35 | [diff] [blame] | 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 | ||||
3 | // found in the LICENSE file. | ||||
4 | |||||
scheib | 0411d8f7 | 2015-10-19 19:29:55 | [diff] [blame] | 5 | // This is a "No Compile Test" suite. |
6 | // http://dev.chromium.org/developers/testing/no-compile-tests | ||||
7 | |||||
[email protected] | 481915a77 | 2011-09-10 03:14:35 | [diff] [blame] | 8 | #include "base/callback.h" |
9 | |||||
10 | namespace base { | ||||
11 | |||||
12 | class Parent { | ||||
13 | }; | ||||
14 | |||||
15 | class Child : Parent { | ||||
16 | }; | ||||
17 | |||||
tzik | 27d1e31 | 2016-09-13 05:28:59 | [diff] [blame] | 18 | #if defined(NCTEST_EQUALS_REQUIRES_SAMETYPE) // [r"fatal error: no viable conversion from 'Callback<int \(\), \[2 \* \.\.\.\]>' to 'const Callback<void \(\), \[2 \* \.\.\.\]>'"] |
[email protected] | 481915a77 | 2011-09-10 03:14:35 | [diff] [blame] | 19 | |
20 | // Attempting to call comparison function on two callbacks of different type. | ||||
21 | // | ||||
22 | // This should be a compile time failure because each callback type should be | ||||
23 | // considered distinct. | ||||
24 | void WontCompile() { | ||||
25 | Closure c1; | ||||
tzik | 3bc7779b | 2015-12-19 09:18:46 | [diff] [blame] | 26 | Callback<int()> c2; |
[email protected] | 481915a77 | 2011-09-10 03:14:35 | [diff] [blame] | 27 | c1.Equals(c2); |
28 | } | ||||
29 | |||||
dcheng | b760d72 | 2014-11-03 21:29:30 | [diff] [blame] | 30 | #elif defined(NCTEST_CONSTRUCTION_FROM_SUBTYPE) // [r"fatal error: no viable conversion from 'Callback<base::Parent \(\)>' to 'Callback<base::Child \(\)>'"] |
[email protected] | 481915a77 | 2011-09-10 03:14:35 | [diff] [blame] | 31 | |
32 | // Construction of Callback<A> from Callback<B> if A is supertype of B. | ||||
33 | // | ||||
34 | // While this is technically safe, most people aren't used to it when coding | ||||
35 | // C++ so if this is happening, it is almost certainly an error. | ||||
36 | void WontCompile() { | ||||
tzik | 3bc7779b | 2015-12-19 09:18:46 | [diff] [blame] | 37 | Callback<Parent()> cb_a; |
38 | Callback<Child()> cb_b = cb_a; | ||||
[email protected] | 481915a77 | 2011-09-10 03:14:35 | [diff] [blame] | 39 | } |
40 | |||||
dcheng | b760d72 | 2014-11-03 21:29:30 | [diff] [blame] | 41 | #elif defined(NCTEST_ASSIGNMENT_FROM_SUBTYPE) // [r"fatal error: no viable overloaded '='"] |
[email protected] | 481915a77 | 2011-09-10 03:14:35 | [diff] [blame] | 42 | |
43 | // Assignment of Callback<A> from Callback<B> if A is supertype of B. | ||||
44 | // See explanation for NCTEST_CONSTRUCTION_FROM_SUBTYPE | ||||
45 | void WontCompile() { | ||||
tzik | 3bc7779b | 2015-12-19 09:18:46 | [diff] [blame] | 46 | Callback<Parent()> cb_a; |
47 | Callback<Child()> cb_b; | ||||
[email protected] | 481915a77 | 2011-09-10 03:14:35 | [diff] [blame] | 48 | cb_a = cb_b; |
49 | } | ||||
50 | |||||
51 | #endif | ||||
52 | |||||
53 | } // namespace base |