callback_list_unittest.nc 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. // Copyright 2013 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. // This is a "No Compile Test" suite.
  5. // http://dev.chromium.org/developers/testing/no-compile-tests
  6. #include "base/callback_list.h"
  7. #include <memory>
  8. #include <utility>
  9. #include "base/bind.h"
  10. #include "base/callback_helpers.h"
  11. namespace base {
  12. class Foo {
  13. public:
  14. Foo() {}
  15. ~Foo() {}
  16. };
  17. class FooListener {
  18. public:
  19. FooListener() = default;
  20. FooListener(const FooListener&) = delete;
  21. FooListener& operator=(const FooListener&) = delete;
  22. void GotAScopedFoo(std::unique_ptr<Foo> f) { foo_ = std::move(f); }
  23. std::unique_ptr<Foo> foo_;
  24. };
  25. #if defined(NCTEST_MOVE_ONLY_TYPE_PARAMETER) // [r"fatal error: call to (implicitly-)?deleted( copy)? constructor"]
  26. // Callbacks run with a move-only typed parameter.
  27. //
  28. // CallbackList does not support move-only typed parameters. Notify() is
  29. // designed to take zero or more parameters, and run each registered callback
  30. // with them. With move-only types, the parameter will be set to NULL after the
  31. // first callback has been run.
  32. void WontCompile() {
  33. FooListener f;
  34. RepeatingCallbackList<void(std::unique_ptr<Foo>)> c1;
  35. CallbackListSubscription sub =
  36. c1.Add(BindRepeating(&FooListener::GotAScopedFoo, Unretained(&f)));
  37. c1.Notify(std::unique_ptr<Foo>(new Foo()));
  38. }
  39. #endif
  40. } // namespace base