123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510 |
- // Copyright (c) 2011 The Chromium Authors. All rights reserved.
- // Use of this source code is governed by a BSD-style license that can be
- // found in the LICENSE file.
- // This is a "No Compile Test" suite.
- // http://dev.chromium.org/developers/testing/no-compile-tests
- #include <utility>
- #include "base/bind.h"
- #include "base/callback.h"
- #include "base/memory/ref_counted.h"
- #include "base/memory/raw_ptr.h"
- #include "base/memory/raw_ref.h"
- #include "base/test/bind.h"
- namespace base {
- // Do not put everything inside an anonymous namespace. If you do, many of the
- // helper function declarations will generate unused definition warnings.
- static const int kParentValue = 1;
- static const int kChildValue = 2;
- class NoRef {
- public:
- void VoidMethod0() {}
- void VoidConstMethod0() const {}
- int IntMethod0() { return 1; }
- };
- class HasRef : public NoRef, public base::RefCounted<HasRef> {
- };
- class Parent {
- public:
- void AddRef() const {}
- void Release() const {}
- virtual void VirtualSet() { value = kParentValue; }
- void NonVirtualSet() { value = kParentValue; }
- int value;
- };
- class Child : public Parent {
- public:
- virtual void VirtualSet() { value = kChildValue; }
- void NonVirtualSet() { value = kChildValue; }
- };
- class NoRefParent {
- public:
- virtual void VirtualSet() { value = kParentValue; }
- void NonVirtualSet() { value = kParentValue; }
- int value;
- };
- class NoRefChild : public NoRefParent {
- virtual void VirtualSet() { value = kChildValue; }
- void NonVirtualSet() { value = kChildValue; }
- };
- template <typename T>
- T PolymorphicIdentity(T t) {
- return t;
- }
- int UnwrapParentRef(Parent& p) {
- return p.value;
- }
- template <typename T>
- void VoidPolymorphic1(T t) {
- }
- void TakesMoveOnly(std::unique_ptr<int>) {
- }
- void TakesIntRef(int& ref) {}
- struct NonEmptyFunctor {
- int x;
- void operator()() const {}
- };
- #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\."]
- // Method bound to const-object.
- //
- // Only const methods should be allowed to work with const objects.
- void WontCompile() {
- HasRef has_ref;
- const HasRef* const_has_ref_ptr_ = &has_ref;
- RepeatingCallback<void()> method_to_const_cb =
- BindRepeating(&HasRef::VoidMethod0, const_has_ref_ptr_);
- method_to_const_cb.Run();
- }
- #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."]
- // Method bound to non-refcounted object.
- //
- // We require refcounts unless you have Unretained().
- void WontCompile() {
- NoRef no_ref;
- RepeatingCallback<void()> no_ref_cb =
- BindRepeating(&NoRef::VoidMethod0, &no_ref);
- no_ref_cb.Run();
- }
- #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."]
- // Const Method bound to non-refcounted object.
- //
- // We require refcounts unless you have Unretained().
- void WontCompile() {
- NoRef no_ref;
- RepeatingCallback<void()> no_ref_const_cb =
- BindRepeating(&NoRef::VoidConstMethod0, &no_ref);
- no_ref_const_cb.Run();
- }
- #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."]
- // Method bound to non-refcounted object.
- //
- // We require refcounts unless you have Unretained().
- void WontCompile() {
- NoRef no_ref;
- raw_ptr<NoRef> rawptr(&no_ref);
- RepeatingCallback<void()> no_ref_cb =
- BindRepeating(&NoRef::VoidMethod0, rawptr);
- no_ref_cb.Run();
- }
- #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."]
- // Const Method bound to non-refcounted object.
- //
- // We require refcounts unless you have Unretained().
- void WontCompile() {
- NoRef no_ref;
- raw_ptr<NoRef> rawptr(&no_ref);
- RepeatingCallback<void()> no_ref_const_cb =
- BindRepeating(&NoRef::VoidConstMethod0, rawptr);
- no_ref_const_cb.Run();
- }
- #elif defined(NCTEST_METHOD_BIND_REF_WRAPPER_RECEIVER_NON_REFCOUNTED_OBJECT) // [r"fatal error: indirection requires pointer operand"]
- // Method bound to non-refcounted object. It fails to compile with
- // std::reference_wrapper.
- void WontCompile() {
- NoRef no_ref;
- RepeatingCallback<void()> no_ref_cb =
- BindRepeating(&NoRef::VoidMethod0, std::cref(no_ref));
- no_ref_cb.Run();
- }
- #elif defined(NCTEST_METHOD_BIND_NATIVE_REF_RECEIVER_NON_REFCOUNTED_OBJECT) // [r"fatal error: indirection requires pointer operand"]
- // Method bound to non-refcounted object. It fails to compile with
- // a native reference.
- void WontCompile() {
- NoRef no_ref;
- RepeatingCallback<void()> no_ref_cb =
- BindRepeating(&NoRef::VoidMethod0, no_ref);
- no_ref_cb.Run();
- }
- #elif defined(NCTEST_METHOD_BIND_RAW_REF_RECEIVER_NON_REFCOUNTED_OBJECT) // [r"fatal error: .*Receivers may not be raw_ref<T>\."]
- // Method bound to non-refcounted object. It fails to compile with
- // a raw_ref.
- void WontCompile() {
- NoRef no_ref;
- raw_ref<NoRef> rawref(no_ref);
- RepeatingCallback<void()> no_ref_cb =
- BindRepeating(&NoRef::VoidMethod0, rawref);
- no_ref_cb.Run();
- }
- #elif defined(NCTEST_METHOD_BIND_REF_WRAPPER_RECEIVER_REFCOUNTED_OBJECT) // [r"fatal error: indirection requires pointer operand"]
- // Method bound to non-refcounted object. It fails to compile with
- // std::reference_wrapper.
- void WontCompile() {
- HasRef has_ref;
- RepeatingCallback<void()> has_ref_cb =
- BindRepeating(&HasRef::VoidMethod0, std::cref(has_ref));
- has_ref_cb.Run();
- }
- #elif defined(NCTEST_METHOD_BIND_NATIVE_REF_RECEIVER_REFCOUNTED_OBJECT) // [r"fatal error: indirection requires pointer operand"]
- // Method bound to non-refcounted object. It fails to compile with
- // a native reference.
- void WontCompile() {
- HasRef has_ref;
- RepeatingCallback<void()> has_ref_cb =
- BindRepeating(&HasRef::VoidMethod0, has_ref);
- has_ref_cb.Run();
- }
- #elif defined(NCTEST_METHOD_BIND_RAW_REF_RECEIVER_REFCOUNTED_OBJECT) // [r"fatal error: .*Receivers may not be raw_ref<T>\."]
- // Method bound to non-refcounted object. It fails to compile with
- // a raw_ref.
- void WontCompile() {
- HasRef has_ref;
- raw_ref<HasRef> rawref(has_ref);
- RepeatingCallback<void()> has_ref_cb =
- BindRepeating(&HasRef::VoidMethod0, rawref);
- has_ref_cb.Run();
- }
- #elif defined(NCTEST_CONST_POINTER) // [r"static assertion failed.+?BindArgument<0>::ForwardedAs<.+?>::ToParamWithType<.+?>::kCanBeForwardedToBoundFunctor.+?Type mismatch between bound argument and bound functor's parameter\."]
- // Const argument used with non-const pointer parameter of same type.
- //
- // This is just a const-correctness check.
- void WontCompile() {
- const NoRef* const_no_ref_ptr;
- RepeatingCallback<NoRef*()> pointer_same_cb =
- BindRepeating(&PolymorphicIdentity<NoRef*>, const_no_ref_ptr);
- pointer_same_cb.Run();
- }
- #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\."]
- // Const argument used with non-const pointer parameter of super type.
- //
- // This is just a const-correctness check.
- void WontCompile() {
- const NoRefChild* const_child_ptr;
- RepeatingCallback<NoRefParent*()> pointer_super_cb =
- BindRepeating(&PolymorphicIdentity<NoRefParent*>, const_child_ptr);
- pointer_super_cb.Run();
- }
- #elif defined(DISABLED_NCTEST_DISALLOW_NON_CONST_REF_PARAM) // [r"fatal error: no member named 'AddRef' in 'base::NoRef'"]
- // TODO(dcheng): I think there's a type safety promotion issue here where we can
- // pass a const ref to a non const-ref function, or vice versa accidentally. Or
- // we make a copy accidentally. Check.
- // Functions with reference parameters, unsupported.
- //
- // First, non-const reference parameters are disallowed by the Google
- // style guide. Second, since we are doing argument forwarding it becomes
- // very tricky to avoid copies, maintain const correctness, and not
- // accidentally have the function be modifying a temporary, or a copy.
- void WontCompile() {
- Parent p;
- RepeatingCallback<int(Parent&)> ref_arg_cb = BindRepeating(&UnwrapParentRef);
- ref_arg_cb.Run(p);
- }
- #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\(\)."]
- // Binding functions with reference parameters requires `std::ref()` or
- // 'base::OwnedRef()`.
- void WontCompile() {
- int v = 1;
- auto cb = BindOnce(&TakesIntRef, v);
- }
- #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\(\)."]
- // Binding functions with reference parameters requires `std::ref()` or
- // 'base::OwnedRef()`.
- void WontCompile() {
- int v = 1;
- auto cb = BindRepeating(&TakesIntRef, v);
- }
- #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."]
- // If the argument and parameter types mismatch then the compile error should be
- // the generic type mismatch error.
- void WontCompile() {
- float f = 1.0f;
- auto cb = BindOnce(&TakesIntRef, f);
- }
- #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."]
- // If the argument and parameter types mismatch then the compile error should be
- // the generic type mismatch error even if the argument is wrapped in
- // base::OwnedRef().
- void WontCompile() {
- float f = 1.0f;
- auto cb = BindOnce(&TakesIntRef, base::OwnedRef(f));
- }
- #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."]
- // A method should not be bindable with an array of objects.
- //
- // This is likely not wanted behavior. We specifically check for it though
- // because it is possible, depending on how you implement prebinding, to
- // implicitly convert an array type to a pointer type.
- void WontCompile() {
- HasRef p[10];
- RepeatingCallback<void()> method_bound_to_array_cb =
- BindRepeating(&HasRef::VoidMethod0, p);
- method_bound_to_array_cb.Run();
- }
- #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."]
- // Refcounted types should not be bound as a raw pointer.
- void WontCompile() {
- HasRef has_ref;
- raw_ref<HasRef> rr(has_ref);
- int a;
- raw_ref<int> rr_a(a);
- RepeatingCallback<void()> ref_count_as_raw_ptr_a =
- BindRepeating(&VoidPolymorphic1<raw_ref<int>>, rr_a);
- RepeatingCallback<void()> ref_count_as_raw_ptr =
- BindRepeating(&VoidPolymorphic1<raw_ref<HasRef>>, rr);
- }
- #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."]
- // Refcounted types should not be bound as a raw pointer.
- void WontCompile() {
- HasRef for_raw_ptr;
- int a;
- RepeatingCallback<void()> ref_count_as_raw_ptr_a =
- BindRepeating(&VoidPolymorphic1<int*>, &a);
- RepeatingCallback<void()> ref_count_as_raw_ptr =
- BindRepeating(&VoidPolymorphic1<HasRef*>, &for_raw_ptr);
- }
- #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."]
- // Refcounted types should not be bound as a raw pointer.
- void WontCompile() {
- HasRef* for_raw_ptr = nullptr;
- RepeatingCallback<void()> ref_count_as_raw_ptr =
- BindRepeating(&VoidPolymorphic1<HasRef*>, for_raw_ptr);
- }
- #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."]
- // Refcounted types should not be bound as a raw pointer.
- void WontCompile() {
- const HasRef for_raw_ptr;
- RepeatingCallback<void()> ref_count_as_raw_ptr =
- BindRepeating(&VoidPolymorphic1<const HasRef*>, &for_raw_ptr);
- }
- #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."]
- // Refcounted types should not be bound as a raw pointer.
- void WontCompile() {
- const HasRef* for_raw_ptr = nullptr;
- RepeatingCallback<void()> ref_count_as_raw_ptr =
- BindRepeating(&VoidPolymorphic1<const HasRef*>, for_raw_ptr);
- }
- #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"]
- // WeakPtrs cannot be bound to methods with return types.
- void WontCompile() {
- NoRef no_ref;
- WeakPtrFactory<NoRef> weak_factory(&no_ref);
- RepeatingCallback<int()> weak_ptr_with_non_void_return_type =
- BindRepeating(&NoRef::IntMethod0, weak_factory.GetWeakPtr());
- weak_ptr_with_non_void_return_type.Run();
- }
- #elif defined(NCTEST_DISALLOW_ASSIGN_DIFFERENT_TYPES) // [r"fatal error: no viable conversion from 'RepeatingCallback<internal::MakeUnboundRunType<void \(\*\)\(int\)>>' to 'RepeatingCallback<void \(\)>'"]
- // Bind result cannot be assigned to Callbacks with a mismatching type.
- void WontCompile() {
- RepeatingClosure callback_mismatches_bind_type =
- BindRepeating(&VoidPolymorphic1<int>);
- }
- #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\."]
- void WontCompile() {
- int i = 0, j = 0;
- BindOnce([i,&j]() {j = i;});
- }
- #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\(\)."]
- void WontCompile() {
- OnceClosure cb = BindOnce([] {});
- cb.Run();
- }
- #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\(\)."]
- void WontCompile() {
- const OnceClosure cb = BindOnce([] {});
- cb.Run();
- }
- #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\(\)."]
- void WontCompile() {
- const OnceClosure cb = BindOnce([] {});
- std::move(cb).Run();
- }
- #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\(\)."]
- void WontCompile() {
- BindRepeating(BindOnce([](int) {}), 42);
- }
- #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))."]
- void WontCompile() {
- auto cb = BindOnce([](int) {});
- BindOnce(cb, 42);
- }
- #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))."]
- void WontCompile() {
- const auto cb = BindOnce([](int) {});
- BindOnce(std::move(cb), 42);
- }
- #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\."]
- void WontCompile() {
- std::unique_ptr<int> x;
- BindOnce(&TakesMoveOnly, x);
- }
- #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\."]
- void WontCompile() {
- std::unique_ptr<int> x;
- BindRepeating(&TakesMoveOnly, x);
- }
- #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\."]
- void WontCompile() {
- std::unique_ptr<int> x;
- BindRepeating(&TakesMoveOnly, std::move(x));
- }
- #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\."]
- void WontCompile() {
- BindRepeating(NonEmptyFunctor());
- }
- #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\)\)."]
- void WontCompile() {
- int foo = 42;
- auto mutable_lambda = [&]() mutable {};
- BindLambdaForTesting(mutable_lambda);
- }
- #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\)\)."]
- void WontCompile() {
- int foo = 42;
- const auto mutable_lambda = [&]() mutable {};
- BindLambdaForTesting(std::move(mutable_lambda));
- }
- #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\?"]
- void WontCompile() {
- struct UncopyableUnmovable {
- UncopyableUnmovable() = default;
- UncopyableUnmovable(const UncopyableUnmovable&) = delete;
- UncopyableUnmovable& operator=(const UncopyableUnmovable&) = delete;
- };
- UncopyableUnmovable u;
- BindOnce([] (const UncopyableUnmovable&) {}, u);
- }
- #elif defined(NCTEST_BIND_ONCE_WITH_PASSED) // [r"static assertion failed.+?Use std::move\(\) instead of base::Passed\(\) with base::BindOnce\(\)"]
- void WontCompile() {
- std::unique_ptr<int> x;
- BindOnce([] (std::unique_ptr<int>) {}, Passed(&x));
- }
- #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\?"]
- void F(int);
- void F(float);
- void WontCompile() {
- BindOnce(&F, 1, 2, 3);
- }
- #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\?"]
- void F(int);
- void F(float);
- void WontCompile() {
- BindRepeating(&F, 1, 2, 3);
- }
- #endif
- } // namespace base
|