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 <utility> 9*635a8641SAndroid Build Coastguard Worker 10*635a8641SAndroid Build Coastguard Worker#include "base/bind.h" 11*635a8641SAndroid Build Coastguard Worker#include "base/callback.h" 12*635a8641SAndroid Build Coastguard Worker#include "base/macros.h" 13*635a8641SAndroid Build Coastguard Worker#include "base/memory/ref_counted.h" 14*635a8641SAndroid Build Coastguard Worker#include "base/test/bind_test_util.h" 15*635a8641SAndroid Build Coastguard Worker 16*635a8641SAndroid Build Coastguard Workernamespace base { 17*635a8641SAndroid Build Coastguard Worker 18*635a8641SAndroid Build Coastguard Worker// Do not put everything inside an anonymous namespace. If you do, many of the 19*635a8641SAndroid Build Coastguard Worker// helper function declarations will generate unused definition warnings. 20*635a8641SAndroid Build Coastguard Worker 21*635a8641SAndroid Build Coastguard Workerstatic const int kParentValue = 1; 22*635a8641SAndroid Build Coastguard Workerstatic const int kChildValue = 2; 23*635a8641SAndroid Build Coastguard Worker 24*635a8641SAndroid Build Coastguard Workerclass NoRef { 25*635a8641SAndroid Build Coastguard Worker public: 26*635a8641SAndroid Build Coastguard Worker void VoidMethod0() {} 27*635a8641SAndroid Build Coastguard Worker void VoidConstMethod0() const {} 28*635a8641SAndroid Build Coastguard Worker int IntMethod0() { return 1; } 29*635a8641SAndroid Build Coastguard Worker}; 30*635a8641SAndroid Build Coastguard Worker 31*635a8641SAndroid Build Coastguard Workerclass HasRef : public NoRef, public base::RefCounted<HasRef> { 32*635a8641SAndroid Build Coastguard Worker}; 33*635a8641SAndroid Build Coastguard Worker 34*635a8641SAndroid Build Coastguard Workerclass Parent { 35*635a8641SAndroid Build Coastguard Worker public: 36*635a8641SAndroid Build Coastguard Worker void AddRef() const {} 37*635a8641SAndroid Build Coastguard Worker void Release() const {} 38*635a8641SAndroid Build Coastguard Worker virtual void VirtualSet() { value = kParentValue; } 39*635a8641SAndroid Build Coastguard Worker void NonVirtualSet() { value = kParentValue; } 40*635a8641SAndroid Build Coastguard Worker int value; 41*635a8641SAndroid Build Coastguard Worker}; 42*635a8641SAndroid Build Coastguard Worker 43*635a8641SAndroid Build Coastguard Workerclass Child : public Parent { 44*635a8641SAndroid Build Coastguard Worker public: 45*635a8641SAndroid Build Coastguard Worker virtual void VirtualSet() { value = kChildValue; } 46*635a8641SAndroid Build Coastguard Worker void NonVirtualSet() { value = kChildValue; } 47*635a8641SAndroid Build Coastguard Worker}; 48*635a8641SAndroid Build Coastguard Worker 49*635a8641SAndroid Build Coastguard Workerclass NoRefParent { 50*635a8641SAndroid Build Coastguard Worker public: 51*635a8641SAndroid Build Coastguard Worker virtual void VirtualSet() { value = kParentValue; } 52*635a8641SAndroid Build Coastguard Worker void NonVirtualSet() { value = kParentValue; } 53*635a8641SAndroid Build Coastguard Worker int value; 54*635a8641SAndroid Build Coastguard Worker}; 55*635a8641SAndroid Build Coastguard Worker 56*635a8641SAndroid Build Coastguard Workerclass NoRefChild : public NoRefParent { 57*635a8641SAndroid Build Coastguard Worker virtual void VirtualSet() { value = kChildValue; } 58*635a8641SAndroid Build Coastguard Worker void NonVirtualSet() { value = kChildValue; } 59*635a8641SAndroid Build Coastguard Worker}; 60*635a8641SAndroid Build Coastguard Worker 61*635a8641SAndroid Build Coastguard Workertemplate <typename T> 62*635a8641SAndroid Build Coastguard WorkerT PolymorphicIdentity(T t) { 63*635a8641SAndroid Build Coastguard Worker return t; 64*635a8641SAndroid Build Coastguard Worker} 65*635a8641SAndroid Build Coastguard Worker 66*635a8641SAndroid Build Coastguard Workerint UnwrapParentRef(Parent& p) { 67*635a8641SAndroid Build Coastguard Worker return p.value; 68*635a8641SAndroid Build Coastguard Worker} 69*635a8641SAndroid Build Coastguard Worker 70*635a8641SAndroid Build Coastguard Workertemplate <typename T> 71*635a8641SAndroid Build Coastguard Workervoid VoidPolymorphic1(T t) { 72*635a8641SAndroid Build Coastguard Worker} 73*635a8641SAndroid Build Coastguard Worker 74*635a8641SAndroid Build Coastguard Workervoid TakesMoveOnly(std::unique_ptr<int>) { 75*635a8641SAndroid Build Coastguard Worker} 76*635a8641SAndroid Build Coastguard Worker 77*635a8641SAndroid Build Coastguard Workerstruct NonEmptyFunctor { 78*635a8641SAndroid Build Coastguard Worker int x; 79*635a8641SAndroid Build Coastguard Worker void operator()() const {} 80*635a8641SAndroid Build Coastguard Worker}; 81*635a8641SAndroid Build Coastguard Worker 82*635a8641SAndroid Build Coastguard Worker// TODO(hans): Remove .* and update the static_assert expectations once we roll 83*635a8641SAndroid Build Coastguard Worker// past Clang r313315. https://crbug.com/765692. 84*635a8641SAndroid Build Coastguard Worker 85*635a8641SAndroid Build Coastguard Worker#if defined(NCTEST_METHOD_ON_CONST_OBJECT) // [r"fatal error: static_assert failed .*\"Bound argument \|i\| of type \|Arg\| cannot be forwarded as \|Unwrapped\| to the bound functor, which declares it as \|Param\|\.\""] 86*635a8641SAndroid Build Coastguard Worker 87*635a8641SAndroid Build Coastguard Worker// Method bound to const-object. 88*635a8641SAndroid Build Coastguard Worker// 89*635a8641SAndroid Build Coastguard Worker// Only const methods should be allowed to work with const objects. 90*635a8641SAndroid Build Coastguard Workervoid WontCompile() { 91*635a8641SAndroid Build Coastguard Worker HasRef has_ref; 92*635a8641SAndroid Build Coastguard Worker const HasRef* const_has_ref_ptr_ = &has_ref; 93*635a8641SAndroid Build Coastguard Worker Callback<void()> method_to_const_cb = 94*635a8641SAndroid Build Coastguard Worker Bind(&HasRef::VoidMethod0, const_has_ref_ptr_); 95*635a8641SAndroid Build Coastguard Worker method_to_const_cb.Run(); 96*635a8641SAndroid Build Coastguard Worker} 97*635a8641SAndroid Build Coastguard Worker 98*635a8641SAndroid Build Coastguard Worker#elif defined(NCTEST_METHOD_BIND_NEEDS_REFCOUNTED_OBJECT) // [r"fatal error: static_assert failed \"Receivers may not be raw pointers\."] 99*635a8641SAndroid Build Coastguard Worker 100*635a8641SAndroid Build Coastguard Worker 101*635a8641SAndroid Build Coastguard Worker// Method bound to non-refcounted object. 102*635a8641SAndroid Build Coastguard Worker// 103*635a8641SAndroid Build Coastguard Worker// We require refcounts unless you have Unretained(). 104*635a8641SAndroid Build Coastguard Workervoid WontCompile() { 105*635a8641SAndroid Build Coastguard Worker NoRef no_ref; 106*635a8641SAndroid Build Coastguard Worker Callback<void()> no_ref_cb = 107*635a8641SAndroid Build Coastguard Worker Bind(&NoRef::VoidMethod0, &no_ref); 108*635a8641SAndroid Build Coastguard Worker no_ref_cb.Run(); 109*635a8641SAndroid Build Coastguard Worker} 110*635a8641SAndroid Build Coastguard Worker 111*635a8641SAndroid Build Coastguard Worker#elif defined(NCTEST_CONST_METHOD_NEEDS_REFCOUNTED_OBJECT) // [r"fatal error: static_assert failed \"Receivers may not be raw pointers\."] 112*635a8641SAndroid Build Coastguard Worker 113*635a8641SAndroid Build Coastguard Worker// Const Method bound to non-refcounted object. 114*635a8641SAndroid Build Coastguard Worker// 115*635a8641SAndroid Build Coastguard Worker// We require refcounts unless you have Unretained(). 116*635a8641SAndroid Build Coastguard Workervoid WontCompile() { 117*635a8641SAndroid Build Coastguard Worker NoRef no_ref; 118*635a8641SAndroid Build Coastguard Worker Callback<void()> no_ref_const_cb = 119*635a8641SAndroid Build Coastguard Worker Bind(&NoRef::VoidConstMethod0, &no_ref); 120*635a8641SAndroid Build Coastguard Worker no_ref_const_cb.Run(); 121*635a8641SAndroid Build Coastguard Worker} 122*635a8641SAndroid Build Coastguard Worker 123*635a8641SAndroid Build Coastguard Worker#elif defined(NCTEST_CONST_POINTER) // [r"fatal error: static_assert failed .*\"Bound argument \|i\| of type \|Arg\| cannot be forwarded as \|Unwrapped\| to the bound functor, which declares it as \|Param\|\.\""] 124*635a8641SAndroid Build Coastguard Worker 125*635a8641SAndroid Build Coastguard Worker// Const argument used with non-const pointer parameter of same type. 126*635a8641SAndroid Build Coastguard Worker// 127*635a8641SAndroid Build Coastguard Worker// This is just a const-correctness check. 128*635a8641SAndroid Build Coastguard Workervoid WontCompile() { 129*635a8641SAndroid Build Coastguard Worker const NoRef* const_no_ref_ptr; 130*635a8641SAndroid Build Coastguard Worker Callback<NoRef*()> pointer_same_cb = 131*635a8641SAndroid Build Coastguard Worker Bind(&PolymorphicIdentity<NoRef*>, const_no_ref_ptr); 132*635a8641SAndroid Build Coastguard Worker pointer_same_cb.Run(); 133*635a8641SAndroid Build Coastguard Worker} 134*635a8641SAndroid Build Coastguard Worker 135*635a8641SAndroid Build Coastguard Worker#elif defined(NCTEST_CONST_POINTER_SUBTYPE) // [r"fatal error: static_assert failed .*\"Bound argument \|i\| of type \|Arg\| cannot be forwarded as \|Unwrapped\| to the bound functor, which declares it as \|Param\|\.\""] 136*635a8641SAndroid Build Coastguard Worker 137*635a8641SAndroid Build Coastguard Worker// Const argument used with non-const pointer parameter of super type. 138*635a8641SAndroid Build Coastguard Worker// 139*635a8641SAndroid Build Coastguard Worker// This is just a const-correctness check. 140*635a8641SAndroid Build Coastguard Workervoid WontCompile() { 141*635a8641SAndroid Build Coastguard Worker const NoRefChild* const_child_ptr; 142*635a8641SAndroid Build Coastguard Worker Callback<NoRefParent*()> pointer_super_cb = 143*635a8641SAndroid Build Coastguard Worker Bind(&PolymorphicIdentity<NoRefParent*>, const_child_ptr); 144*635a8641SAndroid Build Coastguard Worker pointer_super_cb.Run(); 145*635a8641SAndroid Build Coastguard Worker} 146*635a8641SAndroid Build Coastguard Worker 147*635a8641SAndroid Build Coastguard Worker#elif defined(DISABLED_NCTEST_DISALLOW_NON_CONST_REF_PARAM) // [r"fatal error: no member named 'AddRef' in 'base::NoRef'"] 148*635a8641SAndroid Build Coastguard Worker// TODO(dcheng): I think there's a type safety promotion issue here where we can 149*635a8641SAndroid Build Coastguard Worker// pass a const ref to a non const-ref function, or vice versa accidentally. Or 150*635a8641SAndroid Build Coastguard Worker// we make a copy accidentally. Check. 151*635a8641SAndroid Build Coastguard Worker 152*635a8641SAndroid Build Coastguard Worker// Functions with reference parameters, unsupported. 153*635a8641SAndroid Build Coastguard Worker// 154*635a8641SAndroid Build Coastguard Worker// First, non-const reference parameters are disallowed by the Google 155*635a8641SAndroid Build Coastguard Worker// style guide. Second, since we are doing argument forwarding it becomes 156*635a8641SAndroid Build Coastguard Worker// very tricky to avoid copies, maintain const correctness, and not 157*635a8641SAndroid Build Coastguard Worker// accidentally have the function be modifying a temporary, or a copy. 158*635a8641SAndroid Build Coastguard Workervoid WontCompile() { 159*635a8641SAndroid Build Coastguard Worker Parent p; 160*635a8641SAndroid Build Coastguard Worker Callback<int(Parent&)> ref_arg_cb = Bind(&UnwrapParentRef); 161*635a8641SAndroid Build Coastguard Worker ref_arg_cb.Run(p); 162*635a8641SAndroid Build Coastguard Worker} 163*635a8641SAndroid Build Coastguard Worker 164*635a8641SAndroid Build Coastguard Worker#elif defined(NCTEST_DISALLOW_BIND_TO_NON_CONST_REF_PARAM) // [r"fatal error: static_assert failed .*\"Bound argument \|i\| of type \|Arg\| cannot be forwarded as \|Unwrapped\| to the bound functor, which declares it as \|Param\|\.\""] 165*635a8641SAndroid Build Coastguard Worker 166*635a8641SAndroid Build Coastguard Worker// Binding functions with reference parameters, unsupported. 167*635a8641SAndroid Build Coastguard Worker// 168*635a8641SAndroid Build Coastguard Worker// See comment in NCTEST_DISALLOW_NON_CONST_REF_PARAM 169*635a8641SAndroid Build Coastguard Workervoid WontCompile() { 170*635a8641SAndroid Build Coastguard Worker Parent p; 171*635a8641SAndroid Build Coastguard Worker Callback<int()> ref_cb = Bind(&UnwrapParentRef, p); 172*635a8641SAndroid Build Coastguard Worker ref_cb.Run(); 173*635a8641SAndroid Build Coastguard Worker} 174*635a8641SAndroid Build Coastguard Worker 175*635a8641SAndroid Build Coastguard Worker#elif defined(NCTEST_NO_IMPLICIT_ARRAY_PTR_CONVERSION) // [r"fatal error: static_assert failed .*\"First bound argument to a method cannot be an array\.\""] 176*635a8641SAndroid Build Coastguard Worker 177*635a8641SAndroid Build Coastguard Worker// A method should not be bindable with an array of objects. 178*635a8641SAndroid Build Coastguard Worker// 179*635a8641SAndroid Build Coastguard Worker// This is likely not wanted behavior. We specifically check for it though 180*635a8641SAndroid Build Coastguard Worker// because it is possible, depending on how you implement prebinding, to 181*635a8641SAndroid Build Coastguard Worker// implicitly convert an array type to a pointer type. 182*635a8641SAndroid Build Coastguard Workervoid WontCompile() { 183*635a8641SAndroid Build Coastguard Worker HasRef p[10]; 184*635a8641SAndroid Build Coastguard Worker Callback<void()> method_bound_to_array_cb = 185*635a8641SAndroid Build Coastguard Worker Bind(&HasRef::VoidMethod0, p); 186*635a8641SAndroid Build Coastguard Worker method_bound_to_array_cb.Run(); 187*635a8641SAndroid Build Coastguard Worker} 188*635a8641SAndroid Build Coastguard Worker 189*635a8641SAndroid Build Coastguard Worker#elif defined(NCTEST_NO_RVALUE_RAW_PTR_FOR_REFCOUNTED_TYPES) // [r"fatal error: static_assert failed .*\"A parameter is a refcounted type and needs scoped_refptr\.\""] 190*635a8641SAndroid Build Coastguard Worker 191*635a8641SAndroid Build Coastguard Worker// Refcounted types should not be bound as a raw pointer. 192*635a8641SAndroid Build Coastguard Workervoid WontCompile() { 193*635a8641SAndroid Build Coastguard Worker HasRef for_raw_ptr; 194*635a8641SAndroid Build Coastguard Worker int a; 195*635a8641SAndroid Build Coastguard Worker Callback<void()> ref_count_as_raw_ptr_a = 196*635a8641SAndroid Build Coastguard Worker Bind(&VoidPolymorphic1<int*>, &a); 197*635a8641SAndroid Build Coastguard Worker Callback<void()> ref_count_as_raw_ptr = 198*635a8641SAndroid Build Coastguard Worker Bind(&VoidPolymorphic1<HasRef*>, &for_raw_ptr); 199*635a8641SAndroid Build Coastguard Worker} 200*635a8641SAndroid Build Coastguard Worker 201*635a8641SAndroid Build Coastguard Worker#elif defined(NCTEST_NO_LVALUE_RAW_PTR_FOR_REFCOUNTED_TYPES) // [r"fatal error: static_assert failed .*\"A parameter is a refcounted type and needs scoped_refptr\.\""] 202*635a8641SAndroid Build Coastguard Worker 203*635a8641SAndroid Build Coastguard Worker// Refcounted types should not be bound as a raw pointer. 204*635a8641SAndroid Build Coastguard Workervoid WontCompile() { 205*635a8641SAndroid Build Coastguard Worker HasRef* for_raw_ptr = nullptr; 206*635a8641SAndroid Build Coastguard Worker Callback<void()> ref_count_as_raw_ptr = 207*635a8641SAndroid Build Coastguard Worker Bind(&VoidPolymorphic1<HasRef*>, for_raw_ptr); 208*635a8641SAndroid Build Coastguard Worker} 209*635a8641SAndroid Build Coastguard Worker 210*635a8641SAndroid Build Coastguard Worker#elif defined(NCTEST_NO_RVALUE_CONST_RAW_PTR_FOR_REFCOUNTED_TYPES) // [r"fatal error: static_assert failed .*\"A parameter is a refcounted type and needs scoped_refptr\.\""] 211*635a8641SAndroid Build Coastguard Worker 212*635a8641SAndroid Build Coastguard Worker// Refcounted types should not be bound as a raw pointer. 213*635a8641SAndroid Build Coastguard Workervoid WontCompile() { 214*635a8641SAndroid Build Coastguard Worker const HasRef for_raw_ptr; 215*635a8641SAndroid Build Coastguard Worker Callback<void()> ref_count_as_raw_ptr = 216*635a8641SAndroid Build Coastguard Worker Bind(&VoidPolymorphic1<const HasRef*>, &for_raw_ptr); 217*635a8641SAndroid Build Coastguard Worker} 218*635a8641SAndroid Build Coastguard Worker 219*635a8641SAndroid Build Coastguard Worker#elif defined(NCTEST_NO_LVALUE_CONST_RAW_PTR_FOR_REFCOUNTED_TYPES) // [r"fatal error: static_assert failed .*\"A parameter is a refcounted type and needs scoped_refptr\.\""] 220*635a8641SAndroid Build Coastguard Worker 221*635a8641SAndroid Build Coastguard Worker// Refcounted types should not be bound as a raw pointer. 222*635a8641SAndroid Build Coastguard Workervoid WontCompile() { 223*635a8641SAndroid Build Coastguard Worker const HasRef* for_raw_ptr = nullptr; 224*635a8641SAndroid Build Coastguard Worker Callback<void()> ref_count_as_raw_ptr = 225*635a8641SAndroid Build Coastguard Worker Bind(&VoidPolymorphic1<const HasRef*>, for_raw_ptr); 226*635a8641SAndroid Build Coastguard Worker} 227*635a8641SAndroid Build Coastguard Worker 228*635a8641SAndroid Build Coastguard Worker#elif defined(NCTEST_WEAKPTR_BIND_MUST_RETURN_VOID) // [r"fatal error: static_assert failed .*\"weak_ptrs can only bind to methods without return values\""] 229*635a8641SAndroid Build Coastguard Worker 230*635a8641SAndroid Build Coastguard Worker// WeakPtrs cannot be bound to methods with return types. 231*635a8641SAndroid Build Coastguard Workervoid WontCompile() { 232*635a8641SAndroid Build Coastguard Worker NoRef no_ref; 233*635a8641SAndroid Build Coastguard Worker WeakPtrFactory<NoRef> weak_factory(&no_ref); 234*635a8641SAndroid Build Coastguard Worker Callback<int()> weak_ptr_with_non_void_return_type = 235*635a8641SAndroid Build Coastguard Worker Bind(&NoRef::IntMethod0, weak_factory.GetWeakPtr()); 236*635a8641SAndroid Build Coastguard Worker weak_ptr_with_non_void_return_type.Run(); 237*635a8641SAndroid Build Coastguard Worker} 238*635a8641SAndroid Build Coastguard Worker 239*635a8641SAndroid Build Coastguard Worker#elif defined(NCTEST_DISALLOW_ASSIGN_DIFFERENT_TYPES) // [r"fatal error: no viable conversion from 'Callback<MakeUnboundRunType<void \(\*\)\(int\)>>' to 'Callback<void \(\)>'"] 240*635a8641SAndroid Build Coastguard Worker 241*635a8641SAndroid Build Coastguard Worker// Bind result cannot be assigned to Callbacks with a mismatching type. 242*635a8641SAndroid Build Coastguard Workervoid WontCompile() { 243*635a8641SAndroid Build Coastguard Worker Closure callback_mismatches_bind_type = Bind(&VoidPolymorphic1<int>); 244*635a8641SAndroid Build Coastguard Worker} 245*635a8641SAndroid Build Coastguard Worker 246*635a8641SAndroid Build Coastguard Worker#elif defined(NCTEST_DISALLOW_CAPTURING_LAMBDA) // [r"fatal error: implicit instantiation of undefined template 'base::internal::FunctorTraits<\(lambda at (\.\./)+base/bind_unittest.nc:[0-9]+:[0-9]+\), void>'"] 247*635a8641SAndroid Build Coastguard Worker 248*635a8641SAndroid Build Coastguard Workervoid WontCompile() { 249*635a8641SAndroid Build Coastguard Worker int i = 0, j = 0; 250*635a8641SAndroid Build Coastguard Worker Bind([i,&j]() {j = i;}); 251*635a8641SAndroid Build Coastguard Worker} 252*635a8641SAndroid Build Coastguard Worker 253*635a8641SAndroid Build Coastguard Worker#elif defined(NCTEST_DISALLOW_ONCECALLBACK_RUN_ON_LVALUE) // [r"static_assert failed .*\"OnceCallback::Run\(\) may only be invoked on a non-const rvalue, i\.e\. std::move\(callback\)\.Run\(\)\.\""] 254*635a8641SAndroid Build Coastguard Worker 255*635a8641SAndroid Build Coastguard Workervoid WontCompile() { 256*635a8641SAndroid Build Coastguard Worker OnceClosure cb = Bind([] {}); 257*635a8641SAndroid Build Coastguard Worker cb.Run(); 258*635a8641SAndroid Build Coastguard Worker} 259*635a8641SAndroid Build Coastguard Worker 260*635a8641SAndroid Build Coastguard Worker#elif defined(NCTEST_DISALLOW_ONCECALLBACK_RUN_ON_CONST_LVALUE) // [r"static_assert failed .*\"OnceCallback::Run\(\) may only be invoked on a non-const rvalue, i\.e\. std::move\(callback\)\.Run\(\)\.\""] 261*635a8641SAndroid Build Coastguard Worker 262*635a8641SAndroid Build Coastguard Workervoid WontCompile() { 263*635a8641SAndroid Build Coastguard Worker const OnceClosure cb = Bind([] {}); 264*635a8641SAndroid Build Coastguard Worker cb.Run(); 265*635a8641SAndroid Build Coastguard Worker} 266*635a8641SAndroid Build Coastguard Worker 267*635a8641SAndroid Build Coastguard Worker#elif defined(NCTEST_DISALLOW_ONCECALLBACK_RUN_ON_CONST_RVALUE) // [r"static_assert failed .*\"OnceCallback::Run\(\) may only be invoked on a non-const rvalue, i\.e\. std::move\(callback\)\.Run\(\)\.\""] 268*635a8641SAndroid Build Coastguard Worker 269*635a8641SAndroid Build Coastguard Workervoid WontCompile() { 270*635a8641SAndroid Build Coastguard Worker const OnceClosure cb = Bind([] {}); 271*635a8641SAndroid Build Coastguard Worker std::move(cb).Run(); 272*635a8641SAndroid Build Coastguard Worker} 273*635a8641SAndroid Build Coastguard Worker 274*635a8641SAndroid Build Coastguard Worker#elif defined(NCTEST_DISALLOW_BIND_ONCECALLBACK) // [r"fatal error: static_assert failed .*\"BindRepeating cannot bind OnceCallback. Use BindOnce with std::move\(\)\.\""] 275*635a8641SAndroid Build Coastguard Worker 276*635a8641SAndroid Build Coastguard Workervoid WontCompile() { 277*635a8641SAndroid Build Coastguard Worker Bind(BindOnce([](int) {}), 42); 278*635a8641SAndroid Build Coastguard Worker} 279*635a8641SAndroid Build Coastguard Worker 280*635a8641SAndroid Build Coastguard Worker#elif defined(NCTEST_DISALLOW_BINDONCE_LVALUE_ONCECALLBACK) // [r"fatal error: static_assert failed .*\"BindOnce requires non-const rvalue for OnceCallback binding\."] 281*635a8641SAndroid Build Coastguard Workervoid WontCompile() { 282*635a8641SAndroid Build Coastguard Worker auto cb = BindOnce([](int) {}); 283*635a8641SAndroid Build Coastguard Worker BindOnce(cb, 42); 284*635a8641SAndroid Build Coastguard Worker} 285*635a8641SAndroid Build Coastguard Worker 286*635a8641SAndroid Build Coastguard Worker#elif defined(NCTEST_DISALLOW_BINDONCE_RVALUE_CONST_ONCECALLBACK) // [r"fatal error: static_assert failed .*\"BindOnce requires non-const rvalue for OnceCallback binding\."] 287*635a8641SAndroid Build Coastguard Worker 288*635a8641SAndroid Build Coastguard Workervoid WontCompile() { 289*635a8641SAndroid Build Coastguard Worker const auto cb = BindOnce([](int) {}); 290*635a8641SAndroid Build Coastguard Worker BindOnce(std::move(cb), 42); 291*635a8641SAndroid Build Coastguard Worker} 292*635a8641SAndroid Build Coastguard Worker 293*635a8641SAndroid Build Coastguard Worker#elif defined(NCTEST_BINDONCE_MOVEONLY_TYPE_BY_VALUE) // [r"fatal error: static_assert failed .*\"Bound argument \|i\| is move-only but will be bound by copy\. Ensure \|Arg\| is mutable and bound using std::move\(\)\.\""] 294*635a8641SAndroid Build Coastguard Worker 295*635a8641SAndroid Build Coastguard Workervoid WontCompile() { 296*635a8641SAndroid Build Coastguard Worker std::unique_ptr<int> x; 297*635a8641SAndroid Build Coastguard Worker BindOnce(&TakesMoveOnly, x); 298*635a8641SAndroid Build Coastguard Worker} 299*635a8641SAndroid Build Coastguard Worker 300*635a8641SAndroid Build Coastguard Worker#elif defined(NCTEST_BIND_MOVEONLY_TYPE_BY_VALUE) // [r"Bound argument \|i\| is move-only but will be forwarded by copy\. Ensure \|Arg\| is bound using base::Passed\(\), not std::move\(\)."] 301*635a8641SAndroid Build Coastguard Worker 302*635a8641SAndroid Build Coastguard Workervoid WontCompile() { 303*635a8641SAndroid Build Coastguard Worker std::unique_ptr<int> x; 304*635a8641SAndroid Build Coastguard Worker Bind(&TakesMoveOnly, x); 305*635a8641SAndroid Build Coastguard Worker} 306*635a8641SAndroid Build Coastguard Worker 307*635a8641SAndroid Build Coastguard Worker#elif defined(NCTEST_BIND_MOVEONLY_TYPE_WITH_STDMOVE) // [r"Bound argument \|i\| is move-only but will be forwarded by copy\. Ensure \|Arg\| is bound using base::Passed\(\), not std::move\(\)."] 308*635a8641SAndroid Build Coastguard Worker 309*635a8641SAndroid Build Coastguard Workervoid WontCompile() { 310*635a8641SAndroid Build Coastguard Worker std::unique_ptr<int> x; 311*635a8641SAndroid Build Coastguard Worker Bind(&TakesMoveOnly, std::move(x)); 312*635a8641SAndroid Build Coastguard Worker} 313*635a8641SAndroid Build Coastguard Worker 314*635a8641SAndroid Build Coastguard Worker#elif defined(NCTEST_BIND_NON_EMPTY_FUNCTOR) // [r"fatal error: implicit instantiation of undefined template 'base::internal::FunctorTraits<base::NonEmptyFunctor, void>'"] 315*635a8641SAndroid Build Coastguard Worker 316*635a8641SAndroid Build Coastguard Workervoid WontCompile() { 317*635a8641SAndroid Build Coastguard Worker Bind(NonEmptyFunctor()); 318*635a8641SAndroid Build Coastguard Worker} 319*635a8641SAndroid Build Coastguard Worker 320*635a8641SAndroid Build Coastguard Worker#endif 321*635a8641SAndroid Build Coastguard Worker 322*635a8641SAndroid Build Coastguard Worker} // namespace base 323