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