1 // Copyright 2011 The Chromium Authors
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 // This is a "No Compile Test" suite.
6 // http://dev.chromium.org/developers/testing/no-compile-tests
8 #define FORCE_UNRETAINED_COMPLETENESS_CHECKS_FOR_TESTS 1
12 #include "base/functional/bind.h"
13 #include "base/functional/callback.h"
14 #include "base/functional/disallow_unretained.h"
15 #include "base/memory/ref_counted.h"
16 #include "base/memory/raw_ptr.h"
17 #include "base/memory/raw_ref.h"
18 #include "base/test/bind.h"
22 // Do not put everything inside an anonymous namespace. If you do, many of the
23 // helper function declarations will generate unused definition warnings.
25 static const int kParentValue = 1;
26 static const int kChildValue = 2;
31 void VoidConstMethod0() const {}
32 int IntMethod0() { return 1; }
35 class HasRef : public NoRef, public base::RefCounted<HasRef> {
40 void AddRef() const {}
41 void Release() const {}
42 virtual void VirtualSet() { value = kParentValue; }
43 void NonVirtualSet() { value = kParentValue; }
47 class Child : public Parent {
49 virtual void VirtualSet() { value = kChildValue; }
50 void NonVirtualSet() { value = kChildValue; }
55 virtual void VirtualSet() { value = kParentValue; }
56 void NonVirtualSet() { value = kParentValue; }
60 class NoRefChild : public NoRefParent {
61 virtual void VirtualSet() { value = kChildValue; }
62 void NonVirtualSet() { value = kChildValue; }
66 T PolymorphicIdentity(T t) {
70 int UnwrapParentRef(Parent& p) {
75 void VoidPolymorphic1(T t) {
78 void TakesMoveOnly(std::unique_ptr<int>) {
81 void TakesIntRef(int& ref) {}
83 struct NonEmptyFunctor {
85 void operator()() const {}
89 void PassIncompleteByPtr(Incomplete*) {}
95 DISALLOW_UNRETAINED();
98 void PassDangerousByPtr(Dangerous*) {}
99 void PassDangerousByConstRef(const Dangerous&) {}
100 void PassDangerousByMutableRef(Dangerous&) {}
103 #if defined(NCTEST_METHOD_ON_CONST_OBJECT) // [r"static assertion failed.+?BindArgument<0>::ForwardedAs<.+?>::ToParamWithType<.+?>::kCanBeForwardedToBoundFunctor.+?Type mismatch between bound argument and bound functor's parameter\."]
105 // Method bound to const-object.
107 // Only const methods should be allowed to work with const objects.
110 const HasRef* const_has_ref_ptr_ = &has_ref;
111 RepeatingCallback<void()> method_to_const_cb =
112 BindRepeating(&HasRef::VoidMethod0, const_has_ref_ptr_);
113 method_to_const_cb.Run();
116 #elif defined(NCTEST_METHOD_BIND_NEEDS_REFCOUNTED_OBJECT) // [r"fatal error: static assertion failed due to requirement '!IsPointerV<base::NoRef \*> \|\| IsRefCountedType<base::NoRef, void>::value': Receivers may not be raw pointers. If using a raw pointer here is safe and has no lifetime concerns, use base::Unretained\(\) and document why it's safe."]
119 // Method bound to non-refcounted object.
121 // We require refcounts unless you have Unretained().
124 RepeatingCallback<void()> no_ref_cb =
125 BindRepeating(&NoRef::VoidMethod0, &no_ref);
129 #elif defined(NCTEST_CONST_METHOD_BIND_NEEDS_REFCOUNTED_OBJECT) // [r"fatal error: static assertion failed due to requirement '!IsPointerV<base::NoRef \*> \|\| IsRefCountedType<base::NoRef, void>::value': Receivers may not be raw pointers. If using a raw pointer here is safe and has no lifetime concerns, use base::Unretained\(\) and document why it's safe."]
131 // Const Method bound to non-refcounted object.
133 // We require refcounts unless you have Unretained().
136 RepeatingCallback<void()> no_ref_const_cb =
137 BindRepeating(&NoRef::VoidConstMethod0, &no_ref);
138 no_ref_const_cb.Run();
141 #elif defined(NCTEST_METHOD_BIND_RAW_PTR_RECEIVER_NEEDS_REFCOUNTED_OBJECT) // [r"fatal error: static assertion failed due to requirement '!IsPointerV<base::raw_ptr<base::NoRef, [^>]+>?>> \|\| IsRefCountedType<base::NoRef, void>::value': Receivers may not be raw pointers. If using a raw pointer here is safe and has no lifetime concerns, use base::Unretained\(\) and document why it's safe."]
144 // Method bound to non-refcounted object.
146 // We require refcounts unless you have Unretained().
149 raw_ptr<NoRef> rawptr(&no_ref);
150 RepeatingCallback<void()> no_ref_cb =
151 BindRepeating(&NoRef::VoidMethod0, rawptr);
155 #elif defined(NCTEST_CONST_METHOD_BIND_RAW_PTR_RECEIVER_NEEDS_REFCOUNTED_OBJECT) // [r"fatal error: static assertion failed due to requirement '!IsPointerV<base::raw_ptr<base::NoRef, [^>]+>?>> \|\| IsRefCountedType<base::NoRef, void>::value': Receivers may not be raw pointers. If using a raw pointer here is safe and has no lifetime concerns, use base::Unretained\(\) and document why it's safe."]
157 // Const Method bound to non-refcounted object.
159 // We require refcounts unless you have Unretained().
162 raw_ptr<NoRef> rawptr(&no_ref);
163 RepeatingCallback<void()> no_ref_const_cb =
164 BindRepeating(&NoRef::VoidConstMethod0, rawptr);
165 no_ref_const_cb.Run();
168 #elif defined(NCTEST_METHOD_BIND_REF_WRAPPER_RECEIVER_NON_REFCOUNTED_OBJECT) // [r"fatal error: indirection requires pointer operand"]
170 // Method bound to non-refcounted object. It fails to compile with
171 // std::reference_wrapper.
174 RepeatingCallback<void()> no_ref_cb =
175 BindRepeating(&NoRef::VoidMethod0, std::cref(no_ref));
179 #elif defined(NCTEST_METHOD_BIND_NATIVE_REF_RECEIVER_NON_REFCOUNTED_OBJECT) // [r"fatal error: indirection requires pointer operand"]
181 // Method bound to non-refcounted object. It fails to compile with
182 // a native reference.
185 RepeatingCallback<void()> no_ref_cb =
186 BindRepeating(&NoRef::VoidMethod0, no_ref);
190 #elif defined(NCTEST_METHOD_BIND_RAW_REF_RECEIVER_NON_REFCOUNTED_OBJECT) // [r"fatal error: .*Receivers may not be raw_ref<T>\."]
192 // Method bound to non-refcounted object. It fails to compile with
196 raw_ref<NoRef> rawref(no_ref);
197 RepeatingCallback<void()> no_ref_cb =
198 BindRepeating(&NoRef::VoidMethod0, rawref);
202 #elif defined(NCTEST_METHOD_BIND_REF_WRAPPER_RECEIVER_REFCOUNTED_OBJECT) // [r"fatal error: indirection requires pointer operand"]
204 // Method bound to non-refcounted object. It fails to compile with
205 // std::reference_wrapper.
208 RepeatingCallback<void()> has_ref_cb =
209 BindRepeating(&HasRef::VoidMethod0, std::cref(has_ref));
213 #elif defined(NCTEST_METHOD_BIND_NATIVE_REF_RECEIVER_REFCOUNTED_OBJECT) // [r"fatal error: indirection requires pointer operand"]
215 // Method bound to non-refcounted object. It fails to compile with
216 // a native reference.
219 RepeatingCallback<void()> has_ref_cb =
220 BindRepeating(&HasRef::VoidMethod0, has_ref);
224 #elif defined(NCTEST_METHOD_BIND_RAW_REF_RECEIVER_REFCOUNTED_OBJECT) // [r"fatal error: .*Receivers may not be raw_ref<T>\."]
226 // Method bound to non-refcounted object. It fails to compile with
230 raw_ref<HasRef> rawref(has_ref);
231 RepeatingCallback<void()> has_ref_cb =
232 BindRepeating(&HasRef::VoidMethod0, rawref);
236 #elif defined(NCTEST_CONST_POINTER) // [r"static assertion failed.+?BindArgument<0>::ForwardedAs<.+?>::ToParamWithType<.+?>::kCanBeForwardedToBoundFunctor.+?Type mismatch between bound argument and bound functor's parameter\."]
237 // Const argument used with non-const pointer parameter of same type.
239 // This is just a const-correctness check.
241 const NoRef* const_no_ref_ptr;
242 RepeatingCallback<NoRef*()> pointer_same_cb =
243 BindRepeating(&PolymorphicIdentity<NoRef*>, const_no_ref_ptr);
244 pointer_same_cb.Run();
247 #elif defined(NCTEST_CONST_POINTER_SUBTYPE) // [r"static assertion failed.+?BindArgument<0>::ForwardedAs<.+?>::ToParamWithType<.+?>::kCanBeForwardedToBoundFunctor.+?Type mismatch between bound argument and bound functor's parameter\."]
249 // Const argument used with non-const pointer parameter of super type.
251 // This is just a const-correctness check.
253 const NoRefChild* const_child_ptr;
254 RepeatingCallback<NoRefParent*()> pointer_super_cb =
255 BindRepeating(&PolymorphicIdentity<NoRefParent*>, const_child_ptr);
256 pointer_super_cb.Run();
259 #elif defined(DISABLED_NCTEST_DISALLOW_NON_CONST_REF_PARAM) // [r"fatal error: no member named 'AddRef' in 'base::NoRef'"]
260 // TODO(dcheng): I think there's a type safety promotion issue here where we can
261 // pass a const ref to a non const-ref function, or vice versa accidentally. Or
262 // we make a copy accidentally. Check.
264 // Functions with reference parameters, unsupported.
266 // First, non-const reference parameters are disallowed by the Google
267 // style guide. Second, since we are doing argument forwarding it becomes
268 // very tricky to avoid copies, maintain const correctness, and not
269 // accidentally have the function be modifying a temporary, or a copy.
272 RepeatingCallback<int(Parent&)> ref_arg_cb = BindRepeating(&UnwrapParentRef);
276 #elif defined(NCTEST_BIND_ONCE_WITH_NON_CONST_REF_PARAM) // [r"static assertion failed due to requirement 'BindArgument<0>::ForwardedAs<.+?>::ToParamWithType<.+?>::kNonConstRefParamMustBeWrapped': Bound argument for non-const reference parameter must be wrapped in std::ref\(\) or base::OwnedRef\(\)."]
278 // Binding functions with reference parameters requires `std::ref()` or
279 // 'base::OwnedRef()`.
282 auto cb = BindOnce(&TakesIntRef, v);
285 #elif defined(NCTEST_BIND_REPEATING_WITH_NON_CONST_REF_PARAM) // [r"static assertion failed due to requirement 'BindArgument<0>::ForwardedAs<.+?>::ToParamWithType<.+?>::kNonConstRefParamMustBeWrapped': Bound argument for non-const reference parameter must be wrapped in std::ref\(\) or base::OwnedRef\(\)."]
287 // Binding functions with reference parameters requires `std::ref()` or
288 // 'base::OwnedRef()`.
291 auto cb = BindRepeating(&TakesIntRef, v);
294 #elif defined(NCTEST_NON_CONST_REF_PARAM_WRONG_TYPE) // [r"static assertion failed due to requirement 'BindArgument<0>::ForwardedAs<.+?>::ToParamWithType<.+?>::kCanBeForwardedToBoundFunctor': Type mismatch between bound argument and bound functor's parameter."]
296 // If the argument and parameter types mismatch then the compile error should be
297 // the generic type mismatch error.
300 auto cb = BindOnce(&TakesIntRef, f);
303 #elif defined(NCTEST_NON_CONST_REF_PARAM_WRONG_TYPE_AND_WRAPPED) // [r"static assertion failed due to requirement 'BindArgument<0>::ForwardedAs<.+?>::ToParamWithType<.+?>::kCanBeForwardedToBoundFunctor': Type mismatch between bound argument and bound functor's parameter."]
305 // If the argument and parameter types mismatch then the compile error should be
306 // the generic type mismatch error even if the argument is wrapped in
310 auto cb = BindOnce(&TakesIntRef, base::OwnedRef(f));
313 #elif defined(NCTEST_NO_IMPLICIT_ARRAY_PTR_CONVERSION) // [r"fatal error: static assertion failed due to requirement '!std::is_array_v<base::HasRef\[10\]>': First bound argument to a method cannot be an array."]
315 // A method should not be bindable with an array of objects.
317 // This is likely not wanted behavior. We specifically check for it though
318 // because it is possible, depending on how you implement prebinding, to
319 // implicitly convert an array type to a pointer type.
322 RepeatingCallback<void()> method_bound_to_array_cb =
323 BindRepeating(&HasRef::VoidMethod0, p);
324 method_bound_to_array_cb.Run();
327 #elif defined(NCTEST_NO_RVALUE_RAW_REF_FOR_REFCOUNTED_TYPES) // [r"fatal error: static assertion failed due to requirement '!HasRefCountedTypeAsRawPtr<.*raw_ref<base::HasRef,.*: A parameter is a refcounted type and needs scoped_refptr."]
329 // Refcounted types should not be bound as a raw pointer.
332 raw_ref<HasRef> rr(has_ref);
334 raw_ref<int> rr_a(a);
335 RepeatingCallback<void()> ref_count_as_raw_ptr_a =
336 BindRepeating(&VoidPolymorphic1<raw_ref<int>>, rr_a);
337 RepeatingCallback<void()> ref_count_as_raw_ptr =
338 BindRepeating(&VoidPolymorphic1<raw_ref<HasRef>>, rr);
341 #elif defined(NCTEST_NO_RVALUE_RAW_PTR_FOR_REFCOUNTED_TYPES) // [r"fatal error: static assertion failed due to requirement '!HasRefCountedTypeAsRawPtr<base::HasRef \*>::value': A parameter is a refcounted type and needs scoped_refptr."]
343 // Refcounted types should not be bound as a raw pointer.
347 RepeatingCallback<void()> ref_count_as_raw_ptr_a =
348 BindRepeating(&VoidPolymorphic1<int*>, &a);
349 RepeatingCallback<void()> ref_count_as_raw_ptr =
350 BindRepeating(&VoidPolymorphic1<HasRef*>, &for_raw_ptr);
353 #elif defined(NCTEST_NO_LVALUE_RAW_PTR_FOR_REFCOUNTED_TYPES) // [r"fatal error: static assertion failed due to requirement '!HasRefCountedTypeAsRawPtr<base::HasRef \*>::value': A parameter is a refcounted type and needs scoped_refptr."]
355 // Refcounted types should not be bound as a raw pointer.
357 HasRef* for_raw_ptr = nullptr;
358 RepeatingCallback<void()> ref_count_as_raw_ptr =
359 BindRepeating(&VoidPolymorphic1<HasRef*>, for_raw_ptr);
362 #elif defined(NCTEST_NO_RVALUE_CONST_RAW_PTR_FOR_REFCOUNTED_TYPES) // [r"fatal error: static assertion failed due to requirement '!HasRefCountedTypeAsRawPtr<const base::HasRef \*>::value': A parameter is a refcounted type and needs scoped_refptr."]
364 // Refcounted types should not be bound as a raw pointer.
366 const HasRef for_raw_ptr;
367 RepeatingCallback<void()> ref_count_as_raw_ptr =
368 BindRepeating(&VoidPolymorphic1<const HasRef*>, &for_raw_ptr);
371 #elif defined(NCTEST_NO_LVALUE_CONST_RAW_PTR_FOR_REFCOUNTED_TYPES) // [r"fatal error: static assertion failed due to requirement '!HasRefCountedTypeAsRawPtr<const base::HasRef \*>::value': A parameter is a refcounted type and needs scoped_refptr."]
373 // Refcounted types should not be bound as a raw pointer.
375 const HasRef* for_raw_ptr = nullptr;
376 RepeatingCallback<void()> ref_count_as_raw_ptr =
377 BindRepeating(&VoidPolymorphic1<const HasRef*>, for_raw_ptr);
380 #elif defined(NCTEST_WEAKPTR_BIND_MUST_RETURN_VOID) // [r"fatal error: static assertion failed due to requirement 'std::is_void_v<int>': weak_ptrs can only bind to methods without return values"]
382 // WeakPtrs cannot be bound to methods with return types.
385 WeakPtrFactory<NoRef> weak_factory(&no_ref);
386 RepeatingCallback<int()> weak_ptr_with_non_void_return_type =
387 BindRepeating(&NoRef::IntMethod0, weak_factory.GetWeakPtr());
388 weak_ptr_with_non_void_return_type.Run();
391 #elif defined(NCTEST_DISALLOW_ASSIGN_DIFFERENT_TYPES) // [r"fatal error: no viable conversion from 'RepeatingCallback<internal::MakeUnboundRunType<void \(\*\)\(int\)>>' to 'RepeatingCallback<void \(\)>'"]
393 // Bind result cannot be assigned to Callbacks with a mismatching type.
395 RepeatingClosure callback_mismatches_bind_type =
396 BindRepeating(&VoidPolymorphic1<int>);
399 #elif defined(NCTEST_DISALLOW_CAPTURING_LAMBDA) // [r"static assertion failed due to requirement 'FunctorTraits<\(lambda at [^)]+\), void>::is_stateless': Capturing lambdas and stateful lambdas are intentionally not supported\."]
403 BindOnce([i,&j]() {j = i;});
406 #elif defined(NCTEST_DISALLOW_ONCECALLBACK_RUN_ON_LVALUE) // [r"fatal error: static assertion failed due to requirement '!sizeof \(\*this\)': OnceCallback::Run\(\) may only be invoked on a non-const rvalue, i\.e\. std::move\(callback\).Run\(\)."]
409 OnceClosure cb = BindOnce([] {});
413 #elif defined(NCTEST_DISALLOW_ONCECALLBACK_RUN_ON_CONST_LVALUE) // [r"fatal error: static assertion failed due to requirement '!sizeof \(\*this\)': OnceCallback::Run\(\) may only be invoked on a non-const rvalue, i\.e\. std::move\(callback\).Run\(\)."]
416 const OnceClosure cb = BindOnce([] {});
420 #elif defined(NCTEST_DISALLOW_ONCECALLBACK_RUN_ON_CONST_RVALUE) // [r"fatal error: static assertion failed due to requirement '!sizeof \(\*this\)': OnceCallback::Run\(\) may only be invoked on a non-const rvalue, i\.e\. std::move\(callback\).Run\(\)."]
423 const OnceClosure cb = BindOnce([] {});
427 #elif defined(NCTEST_DISALLOW_BIND_ONCECALLBACK) // [r"fatal error: static assertion failed due to requirement '!base::internal::IsOnceCallback<base::OnceCallback<void \(int\)> ?>\(\)': BindRepeating cannot bind OnceCallback. Use BindOnce with std::move\(\)."]
430 BindRepeating(BindOnce([](int) {}), 42);
433 #elif defined(NCTEST_DISALLOW_BINDONCE_LVALUE_ONCECALLBACK) // [r"fatal error: static assertion failed due to requirement '!internal::IsOnceCallback<std::decay_t<OnceCallback<void (int)> &> >() || (std::is_rvalue_reference<OnceCallback<void (int)> &>() && !std::is_const<std::remove_reference_t<OnceCallback<void (int)> &> >())': BindOnce requires non-const rvalue for OnceCallback binding. I.e.: base::BindOnce(std::move(callback))."]
435 auto cb = BindOnce([](int) {});
439 #elif defined(NCTEST_DISALLOW_BINDONCE_RVALUE_CONST_ONCECALLBACK) // [r"fatal error: static assertion failed due to requirement '!internal::IsOnceCallback<std::decay_t<const OnceCallback<void (int)> > >() || (std::is_rvalue_reference<const OnceCallback<void (int)> &&>() && !std::is_const<std::remove_reference_t<const OnceCallback<void (int)> > >())': BindOnce requires non-const rvalue for OnceCallback binding. I.e.: base::BindOnce(std::move(callback))."]
442 const auto cb = BindOnce([](int) {});
443 BindOnce(std::move(cb), 42);
446 #elif defined(NCTEST_BINDONCE_MOVEONLY_TYPE_BY_VALUE) // [r"static assertion failed.+?BindArgument<0>::BoundAs<.+?>::StoredAs<.+?>::kMoveOnlyTypeMustUseStdMove.+?Attempting to bind a move-only type\. Use std::move\(\) to transfer ownership to the created callback\."]
449 std::unique_ptr<int> x;
450 BindOnce(&TakesMoveOnly, x);
453 #elif defined(NCTEST_BIND_MOVEONLY_TYPE_BY_VALUE) // [r"static assertion failed.+?BindArgument<0>::ForwardedAs<.+?>::ToParamWithType<.+?>::kMoveOnlyTypeMustUseBasePassed.+?base::BindRepeating\(\) argument is a move-only type\. Use base::Passed\(\) instead of std::move\(\) to transfer ownership from the callback to the bound functor\."]
456 std::unique_ptr<int> x;
457 BindRepeating(&TakesMoveOnly, x);
460 #elif defined(NCTEST_BIND_MOVEONLY_TYPE_WITH_STDMOVE) // [r"static assertion failed.+?BindArgument<0>::ForwardedAs<.+?>::ToParamWithType<.+?>::kMoveOnlyTypeMustUseBasePassed.+?base::BindRepeating\(\) argument is a move-only type\. Use base::Passed\(\) instead of std::move\(\) to transfer ownership from the callback to the bound functor\."]
463 std::unique_ptr<int> x;
464 BindRepeating(&TakesMoveOnly, std::move(x));
467 #elif defined(NCTEST_BIND_NON_EMPTY_FUNCTOR) // [r"static assertion failed due to requirement 'FunctorTraits<base::NonEmptyFunctor, void>::is_stateless': Capturing lambdas and stateful lambdas are intentionally not supported\."]
470 BindRepeating(NonEmptyFunctor());
473 #elif defined(NCTEST_DISALLOW_BINDLAMBDAFORTESTING_LVALUE_MUTABLE_LAMBDA) // [r"BindLambdaForTesting requires non-const rvalue for mutable lambda binding\. I\.e\.: base::BindLambdaForTesting\(std::move\(lambda\)\)."]
476 auto mutable_lambda = [&]() mutable {};
477 BindLambdaForTesting(mutable_lambda);
480 #elif defined(NCTEST_DISALLOW_BINDLAMBDAFORTESTING_RVALUE_CONST_MUTABLE_LAMBDA) // [r"BindLambdaForTesting requires non-const rvalue for mutable lambda binding\. I\.e\.: base::BindLambdaForTesting\(std::move\(lambda\)\)."]
484 const auto mutable_lambda = [&]() mutable {};
485 BindLambdaForTesting(std::move(mutable_lambda));
488 #elif defined(NCTEST_BIND_UNCOPYABLE_AND_UNMOVABLE_TYPE) // [r"static assertion failed.+?BindArgument<0>::BoundAs<.+?>::StoredAs<.+?>::kBindArgumentCanBeCaptured.+?Cannot capture argument: is the argument copyable or movable\?"]
491 struct UncopyableUnmovable {
492 UncopyableUnmovable() = default;
493 UncopyableUnmovable(const UncopyableUnmovable&) = delete;
494 UncopyableUnmovable& operator=(const UncopyableUnmovable&) = delete;
497 UncopyableUnmovable u;
498 BindOnce([] (const UncopyableUnmovable&) {}, u);
501 #elif defined(NCTEST_BIND_ONCE_WITH_PASSED) // [r"static assertion failed.+?Use std::move\(\) instead of base::Passed\(\) with base::BindOnce\(\)"]
504 std::unique_ptr<int> x;
505 BindOnce([] (std::unique_ptr<int>) {}, Passed(&x));
508 #elif defined(NCTEST_BIND_ONCE_WITH_ADDRESS_OF_OVERLOADED_FUNCTION) // [r"fatal error: reference to overloaded function could not be resolved; did you mean to call it\?"]
514 BindOnce(&F, 1, 2, 3);
517 #elif defined(NCTEST_BIND_REPEATING_WITH_ADDRESS_OF_OVERLOADED_FUNCTION) // [r"fatal error: reference to overloaded function could not be resolved; did you mean to call it\?"]
523 BindRepeating(&F, 1, 2, 3);
526 #elif defined(NCTEST_UNRETAINED_WITH_INCOMPLETE_TYPE) // [r"fatal error: .+ T must be fully defined\."]
528 void WontCompile(Incomplete* incomplete) {
529 BindOnce(&PassIncompleteByPtr, base::Unretained(incomplete));
532 #elif defined(NCTEST_RAW_POINTER_WITH_INCOMPLETE_TYPE) // [r"fatal error: .+ T must be fully defined\."]
534 void WontCompile(Incomplete* incomplete) {
535 BindOnce(&PassIncompleteByPtr, incomplete);
538 #elif defined(NCTEST_UNRETAINED_WITH_DISALLOWED_TYPE) // [r"fatal error: static assertion failed due to requirement 'TypeSupportsUnretainedV"]
542 BindOnce(&Dangerous::Method, base::Unretained(&dangerous));
545 #elif defined(NCTEST_RAW_POINTER_WITH_DISALLOWED_TYPE) // [r"fatal error: static assertion failed due to requirement 'TypeSupportsUnretainedV"]
549 BindOnce(&PassDangerousByPtr, &dangerous);
552 #elif defined(NCTEST_RAW_CONST_REFERENCE_WITH_DISALLOWED_TYPE) // [r"fatal error: static assertion failed due to requirement 'TypeSupportsUnretainedV"]
556 BindOnce(&PassDangerousByConstRef, std::cref(dangerous));
559 #elif defined(NCTEST_RAW_MUTABLE_REFERENCE_WITH_DISALLOWED_TYPE) // [r"fatal error: static assertion failed due to requirement 'TypeSupportsUnretainedV"]
563 BindOnce(&PassDangerousByMutableRef, std::ref(dangerous));
566 #elif defined(NCTEST_UNSAFE_DANLING_WITHOUT_RAW_PTR_RECEIVER) // [r"fatal error: static assertion failed.+?base::UnsafeDangling\(\) pointers must be received by functors with MayBeDangling<T> as parameter\."]
568 void PassIntPtr(int *ptr) {}
572 BindOnce(&PassIntPtr, UnsafeDangling(&val));
575 #elif defined(NCTEST_UNSAFE_DANLING_WITH_DIFFERENT_PTR_TRAITS) // [r"fatal error: static assertion failed.+?MayBeDangling<T> parameter must receive the same RawPtrTraits as the one passed to the corresponding base::UnsafeDangling\(\) call\."]
577 void PassIntPtr(MayBeDangling<int> ptr) {}
581 BindOnce(&PassIntPtr, UnsafeDangling<int, RawPtrTraits::kDummyForTest>(&val));
584 #elif defined(NCTEST_UNSAFE_DANLING_UNTRIAGED_WITH_RAW_PTR_RECEIVER) // [r"base::Bind\(\) target functor has a parameter of type raw_ptr<T>."]
586 void PassIntRawPtr(raw_ptr<int> ptr) {}
590 BindOnce(&PassIntRawPtr, UnsafeDanglingUntriaged(&val));