1*635a8641SAndroid Build Coastguard Worker// Copyright (c) 2011 The Chromium Authors. All rights reserved. 2*635a8641SAndroid Build Coastguard Worker// Use of this source code is governed by a BSD-style license that can be 3*635a8641SAndroid Build Coastguard Worker// found in the LICENSE file. 4*635a8641SAndroid Build Coastguard Worker 5*635a8641SAndroid Build Coastguard Worker// This is a "No Compile Test" suite. 6*635a8641SAndroid Build Coastguard Worker// http://dev.chromium.org/developers/testing/no-compile-tests 7*635a8641SAndroid Build Coastguard Worker 8*635a8641SAndroid Build Coastguard Worker#include "base/callback.h" 9*635a8641SAndroid Build Coastguard Worker 10*635a8641SAndroid Build Coastguard Workernamespace base { 11*635a8641SAndroid Build Coastguard Worker 12*635a8641SAndroid Build Coastguard Workerclass Parent { 13*635a8641SAndroid Build Coastguard Worker}; 14*635a8641SAndroid Build Coastguard Worker 15*635a8641SAndroid Build Coastguard Workerclass Child : Parent { 16*635a8641SAndroid Build Coastguard Worker}; 17*635a8641SAndroid Build Coastguard Worker 18*635a8641SAndroid Build Coastguard Worker#if defined(NCTEST_EQUALS_REQUIRES_SAMETYPE) // [r"fatal error: no viable conversion from 'RepeatingCallback<int \(\)>' to 'const RepeatingCallback<void \(\)>'"] 19*635a8641SAndroid Build Coastguard Worker 20*635a8641SAndroid Build Coastguard Worker// Attempting to call comparison function on two callbacks of different type. 21*635a8641SAndroid Build Coastguard Worker// 22*635a8641SAndroid Build Coastguard Worker// This should be a compile time failure because each callback type should be 23*635a8641SAndroid Build Coastguard Worker// considered distinct. 24*635a8641SAndroid Build Coastguard Workervoid WontCompile() { 25*635a8641SAndroid Build Coastguard Worker Closure c1; 26*635a8641SAndroid Build Coastguard Worker Callback<int()> c2; 27*635a8641SAndroid Build Coastguard Worker c1.Equals(c2); 28*635a8641SAndroid Build Coastguard Worker} 29*635a8641SAndroid Build Coastguard Worker 30*635a8641SAndroid Build Coastguard Worker#elif defined(NCTEST_CONSTRUCTION_FROM_SUBTYPE) // [r"fatal error: no viable conversion from 'Callback<base::Parent \(\)>' to 'Callback<base::Child \(\)>'"] 31*635a8641SAndroid Build Coastguard Worker 32*635a8641SAndroid Build Coastguard Worker// Construction of Callback<A> from Callback<B> if A is supertype of B. 33*635a8641SAndroid Build Coastguard Worker// 34*635a8641SAndroid Build Coastguard Worker// While this is technically safe, most people aren't used to it when coding 35*635a8641SAndroid Build Coastguard Worker// C++ so if this is happening, it is almost certainly an error. 36*635a8641SAndroid Build Coastguard Workervoid WontCompile() { 37*635a8641SAndroid Build Coastguard Worker Callback<Parent()> cb_a; 38*635a8641SAndroid Build Coastguard Worker Callback<Child()> cb_b = cb_a; 39*635a8641SAndroid Build Coastguard Worker} 40*635a8641SAndroid Build Coastguard Worker 41*635a8641SAndroid Build Coastguard Worker#elif defined(NCTEST_ASSIGNMENT_FROM_SUBTYPE) // [r"fatal error: no viable overloaded '='"] 42*635a8641SAndroid Build Coastguard Worker 43*635a8641SAndroid Build Coastguard Worker// Assignment of Callback<A> from Callback<B> if A is supertype of B. 44*635a8641SAndroid Build Coastguard Worker// See explanation for NCTEST_CONSTRUCTION_FROM_SUBTYPE 45*635a8641SAndroid Build Coastguard Workervoid WontCompile() { 46*635a8641SAndroid Build Coastguard Worker Callback<Parent()> cb_a; 47*635a8641SAndroid Build Coastguard Worker Callback<Child()> cb_b; 48*635a8641SAndroid Build Coastguard Worker cb_a = cb_b; 49*635a8641SAndroid Build Coastguard Worker} 50*635a8641SAndroid Build Coastguard Worker 51*635a8641SAndroid Build Coastguard Worker#endif 52*635a8641SAndroid Build Coastguard Worker 53*635a8641SAndroid Build Coastguard Worker} // namespace base 54