diff --git a/eventuals/builder.h b/eventuals/builder.h index e89b6210f..a1318abd9 100644 --- a/eventuals/builder.h +++ b/eventuals/builder.h @@ -18,6 +18,14 @@ class Field; template class Field { public: + Field() = default; + + Field(const Field&) = default; + Field(Field&&) noexcept = default; + + Field& operator=(const Field&) = default; + Field& operator=(Field&&) noexcept = default; + virtual ~Field() = default; template @@ -33,6 +41,12 @@ class Field { Field(Value_ value) : value_(std::move(value)) {} + Field(const Field&) = default; + Field(Field&&) noexcept = default; + + Field& operator=(const Field&) = default; + Field& operator=(Field&&) noexcept = default; + virtual ~Field() = default; auto& value() & { @@ -77,8 +91,12 @@ class FieldWithDefault final : public Field { FieldWithDefault(Value&& value) : default_(std::forward(value)) {} + FieldWithDefault(const FieldWithDefault&) = delete; FieldWithDefault(FieldWithDefault&&) noexcept = default; + FieldWithDefault& operator=(const FieldWithDefault&) = delete; + FieldWithDefault& operator=(FieldWithDefault&&) noexcept = delete; + ~FieldWithDefault() override = default; template @@ -124,8 +142,12 @@ class FieldWithDefault final : public Field { FieldWithDefault(Value&& value) : Field(std::forward(value)) {} + FieldWithDefault(const FieldWithDefault&) = delete; FieldWithDefault(FieldWithDefault&&) noexcept = default; + FieldWithDefault& operator=(const FieldWithDefault&) = delete; + FieldWithDefault& operator=(FieldWithDefault&&) noexcept = delete; + ~FieldWithDefault() override = default; }; @@ -143,8 +165,12 @@ class RepeatedField final : public Field { RepeatedField(Value&& value) : default_(std::forward(value)) {} + RepeatedField(const RepeatedField&) = delete; RepeatedField(RepeatedField&&) noexcept = default; + RepeatedField& operator=(const RepeatedField&) = delete; + RepeatedField& operator=(RepeatedField&&) noexcept = delete; + ~RepeatedField() override = default; template @@ -190,8 +216,12 @@ class RepeatedField final : public Field { RepeatedField(Value&& value) : Field(std::forward(value)) {} + RepeatedField(const RepeatedField&) = delete; RepeatedField(RepeatedField&&) noexcept = default; + RepeatedField& operator=(const RepeatedField&) = delete; + RepeatedField& operator=(RepeatedField&&) noexcept = delete; + ~RepeatedField() override = default; template @@ -205,6 +235,14 @@ class RepeatedField final : public Field { class Builder { public: + Builder() = default; + + Builder(const Builder&) = default; + Builder(Builder&&) noexcept = default; + + Builder& operator=(const Builder&) = default; + Builder& operator=(Builder&&) noexcept = default; + virtual ~Builder() = default; protected: diff --git a/eventuals/callback.h b/eventuals/callback.h index 057564e49..56cf109dc 100644 --- a/eventuals/callback.h +++ b/eventuals/callback.h @@ -35,6 +35,18 @@ struct Callback final { this->operator=(std::move(f)); } + Callback(const Callback&) = delete; + + Callback(Callback&& that) noexcept { + if (that.base_ != nullptr) { + base_ = that.base_->Move(&storage_); + + // Set 'base_' to nullptr so we only destruct once. + that.base_ = nullptr; + } + } + + Callback& operator=(const Callback&) = delete; Callback& operator=(Callback&& that) noexcept { if (this == &that) { return *this; @@ -77,15 +89,6 @@ struct Callback final { return *this; } - Callback(Callback&& that) noexcept { - if (that.base_ != nullptr) { - base_ = that.base_->Move(&storage_); - - // Set 'base_' to nullptr so we only destruct once. - that.base_ = nullptr; - } - } - ~Callback() { if (base_ != nullptr) { base_->~Base(); @@ -102,6 +105,14 @@ struct Callback final { } struct Base { + Base() = default; + + Base(const Base&) = default; + Base(Base&&) noexcept = default; + + Base& operator=(const Base&) = default; + Base& operator=(Base&&) noexcept = default; + virtual ~Base() = default; virtual R Invoke(Args... args) = 0; @@ -114,6 +125,12 @@ struct Callback final { Handler(F f) : f_(std::move(f)) {} + Handler(const Handler&) = default; + Handler(Handler&&) noexcept = default; + + Handler& operator=(const Handler&) = default; + Handler& operator=(Handler&&) noexcept = default; + ~Handler() override = default; R Invoke(Args... args) override { diff --git a/eventuals/concurrent-ordered.h b/eventuals/concurrent-ordered.h index 67b6028c0..5ed97e8cc 100644 --- a/eventuals/concurrent-ordered.h +++ b/eventuals/concurrent-ordered.h @@ -26,8 +26,12 @@ struct _ReorderAdaptor final { Continuation(K_ k) : k_(std::move(k)) {} + Continuation(const Continuation&) = delete; Continuation(Continuation&& that) noexcept = default; + Continuation& operator=(const Continuation&) = delete; + Continuation& operator=(Continuation&&) noexcept = delete; + ~Continuation() override = default; void Begin(TypeErasedStream& stream) { @@ -150,6 +154,12 @@ struct _ConcurrentOrderedAdaptor final { Continuation(K_ k) : k_(std::move(k)) {} + Continuation(const Continuation&) = default; + Continuation(Continuation&&) noexcept = default; + + Continuation& operator=(const Continuation&) = default; + Continuation& operator=(Continuation&&) noexcept = default; + ~Continuation() override = default; void Begin(TypeErasedStream& stream) { diff --git a/eventuals/concurrent.h b/eventuals/concurrent.h index 0d0576463..566d52a6c 100644 --- a/eventuals/concurrent.h +++ b/eventuals/concurrent.h @@ -70,6 +70,20 @@ struct _Concurrent final { // that have completed but haven't yet been pruned (see // 'CreateOrReuseFiber()'). struct TypeErasedFiber { + TypeErasedFiber() = default; + + // Constructors and assignment operators are deleted, because + // 'Interrupt' class has std::atomic (which is not copyable/moveable), + // and doesn't provide its own copy/move constructors/assignment + // operators. + TypeErasedFiber(const TypeErasedFiber&) = delete; + TypeErasedFiber(TypeErasedFiber&&) noexcept = delete; + + TypeErasedFiber& operator=(const TypeErasedFiber&) = delete; + TypeErasedFiber& operator=(TypeErasedFiber&&) = delete; + + virtual ~TypeErasedFiber() = default; + void Reuse() { done = false; // Need to reinitialize the interrupt so that the @@ -79,8 +93,6 @@ struct _Concurrent final { new (&interrupt) class Interrupt(); } - virtual ~TypeErasedFiber() = default; - // A fiber indicates it is done with this boolean. bool done = false; @@ -432,6 +444,12 @@ struct _Concurrent final { Adaptor(F_ f) : f_(std::move(f)) {} + Adaptor(const Adaptor&) = default; + Adaptor(Adaptor&&) noexcept = default; + + Adaptor& operator=(const Adaptor&) = default; + Adaptor& operator=(Adaptor&&) noexcept = default; + ~Adaptor() override = default; // Our typeful fiber includes the continuation 'K' that we'll @@ -585,11 +603,16 @@ struct _Concurrent final { : adaptor_(std::move(f)), k_(std::move(k)) {} + Continuation(const Continuation&) = delete; + // NOTE: explicit move-constructor because of 'std::atomic_flag'. Continuation(Continuation&& that) noexcept : adaptor_(std::move(that.adaptor_.f_)), k_(std::move(that.k_)) {} + Continuation& operator=(const Continuation&) = delete; + Continuation& operator=(Continuation&&) noexcept = delete; + ~Continuation() override = default; void Begin(TypeErasedStream& stream) { diff --git a/eventuals/do-all.h b/eventuals/do-all.h index ac6baf969..8bf2c62ed 100644 --- a/eventuals/do-all.h +++ b/eventuals/do-all.h @@ -21,6 +21,8 @@ struct _DoAll final { : k_(k), interrupt_(interrupt) {} + Adaptor(const Adaptor&) = delete; + Adaptor(Adaptor&& that) noexcept : k_(that.k_), interrupt_(that.interrupt_) { @@ -28,6 +30,11 @@ struct _DoAll final { << "moving after starting is illegal"; } + Adaptor& operator=(const Adaptor&) = delete; + Adaptor& operator=(Adaptor&&) noexcept = delete; + + ~Adaptor() = default; + K_& k_; Interrupt& interrupt_; @@ -190,6 +197,8 @@ struct _DoAll final { : eventuals_(std::move(eventuals)), k_(std::move(k)) {} + Continuation(const Continuation&) = delete; + Continuation(Continuation&& that) noexcept : eventuals_(std::move(that.eventuals_)), adaptor_(std::move(that.adaptor_)), @@ -197,6 +206,11 @@ struct _DoAll final { handler_(std::move(that.handler_)), k_(std::move(that.k_)) {} + Continuation& operator=(const Continuation&) = delete; + Continuation& operator=(Continuation&&) noexcept = delete; + + ~Continuation() = default; + template void Start(Args&&...) { adaptor_.emplace(k_, interrupt_); diff --git a/eventuals/event-loop.h b/eventuals/event-loop.h index 1c009dde5..14502a3e7 100644 --- a/eventuals/event-loop.h +++ b/eventuals/event-loop.h @@ -153,11 +153,17 @@ class EventLoop final : public Scheduler { class Clock final : public stout::enable_borrowable_from_this { public: - Clock(const Clock&) = delete; - Clock(EventLoop& loop) : loop_(loop) {} + Clock(const Clock&) = delete; + Clock(Clock&&) noexcept = delete; + + Clock& operator=(const Clock&) = delete; + Clock& operator=(Clock&&) noexcept = delete; + + ~Clock() override = default; + std::chrono::nanoseconds Now(); auto Timer(std::chrono::nanoseconds nanoseconds); @@ -204,6 +210,8 @@ class EventLoop final : public Scheduler { interrupt_context_(&clock_->loop(), "Timer (interrupt)"), k_(std::move(k)) {} + Continuation(const Continuation&) = delete; + Continuation(Continuation&& that) noexcept : clock_(std::move(that.clock_)), nanoseconds_(std::move(that.nanoseconds_)), @@ -214,6 +222,9 @@ class EventLoop final : public Scheduler { CHECK(!handler_); } + Continuation& operator=(const Continuation&) = delete; + Continuation& operator=(Continuation&&) noexcept = delete; + ~Continuation() { CHECK(!started_ || closed_); } @@ -462,7 +473,13 @@ class EventLoop final : public Scheduler { static void ConstructDefaultAndRunForeverDetached(); EventLoop(); + EventLoop(const EventLoop&) = delete; + EventLoop(EventLoop&&) noexcept = delete; + + EventLoop& operator=(const EventLoop&) = delete; + EventLoop& operator=(EventLoop&&) noexcept = delete; + ~EventLoop() override; void RunForever(); @@ -555,6 +572,8 @@ class EventLoop final : public Scheduler { interrupt_context_(&loop, "WaitForSignal (interrupt)"), k_(std::move(k)) {} + Continuation(const Continuation&) = delete; + Continuation(Continuation&& that) noexcept : loop_(that.loop_), signum_(that.signum_), @@ -565,6 +584,9 @@ class EventLoop final : public Scheduler { CHECK(!handler_); } + Continuation& operator=(const Continuation&) = delete; + Continuation& operator=(Continuation&&) noexcept = delete; + ~Continuation() { CHECK(!started_ || closed_); } @@ -775,6 +797,8 @@ class EventLoop final : public Scheduler { interrupt_context_(&loop, "Poll (interrupt)"), k_(std::move(k)) {} + Continuation(const Continuation&) = delete; + Continuation(Continuation&& that) noexcept : loop_(that.loop_), fd_(that.fd_), @@ -786,6 +810,9 @@ class EventLoop final : public Scheduler { CHECK(!handler_); } + Continuation& operator=(const Continuation&) = delete; + Continuation& operator=(Continuation&&) noexcept = delete; + ~Continuation() { CHECK(!started_ || closed_); } diff --git a/eventuals/eventual.h b/eventuals/eventual.h index 1cb98793c..a66f83d51 100644 --- a/eventuals/eventual.h +++ b/eventuals/eventual.h @@ -80,8 +80,11 @@ struct _Eventual { stop_(std::move(stop)), k_(std::move(k)) {} + Continuation(const Continuation&) = delete; Continuation(Continuation&& that) noexcept = default; + Continuation& operator=(const Continuation&) = delete; + Continuation& operator=(Continuation&& that) noexcept { if (this == &that) { return *this; @@ -97,6 +100,8 @@ struct _Eventual { return *this; } + ~Continuation() = default; + template void Start(Args&&... args) { static_assert( diff --git a/eventuals/flat-map.h b/eventuals/flat-map.h index 1e243ed06..9b9f46b04 100644 --- a/eventuals/flat-map.h +++ b/eventuals/flat-map.h @@ -61,8 +61,12 @@ struct _FlatMap final { : f_(std::move(f)), k_(std::move(k)) {} + Continuation(const Continuation&) = delete; Continuation(Continuation&& that) noexcept = default; + Continuation& operator=(const Continuation&) = delete; + Continuation& operator=(Continuation&&) noexcept = delete; + ~Continuation() override = default; void Begin(TypeErasedStream& stream) { diff --git a/eventuals/generator.h b/eventuals/generator.h index 1764825b4..fd82662b2 100644 --- a/eventuals/generator.h +++ b/eventuals/generator.h @@ -456,9 +456,13 @@ struct _Generator final { }; } - ~Composable() = default; + Composable(const Composable&) = delete; + Composable(Composable&&) noexcept = default; + + Composable& operator=(const Composable&) = delete; + Composable& operator=(Composable&&) noexcept = delete; - Composable(Composable&& that) noexcept = default; + ~Composable() = default; template auto k(K k) && { diff --git a/eventuals/http.cc b/eventuals/http.cc index 5e4e7ad8c..ff5ca0077 100644 --- a/eventuals/http.cc +++ b/eventuals/http.cc @@ -12,6 +12,12 @@ class CURLGlobalInitializer final { CHECK_EQ(curl_global_init(CURL_GLOBAL_ALL), 0); } + CURLGlobalInitializer(const CURLGlobalInitializer&) = default; + CURLGlobalInitializer(CURLGlobalInitializer&&) noexcept = default; + + CURLGlobalInitializer& operator=(const CURLGlobalInitializer&) = default; + CURLGlobalInitializer& operator=(CURLGlobalInitializer&&) noexcept = default; + ~CURLGlobalInitializer() { curl_global_cleanup(); } diff --git a/eventuals/http.h b/eventuals/http.h index 639d9e6a7..6ea0bb44b 100644 --- a/eventuals/http.h +++ b/eventuals/http.h @@ -100,6 +100,12 @@ template < bool has_headers_> class Request::_Builder final : public builder::Builder { public: + _Builder(const _Builder&) = default; + _Builder(_Builder&&) noexcept = default; + + _Builder& operator=(const _Builder&) = default; + _Builder& operator=(_Builder&&) noexcept = default; + ~_Builder() override = default; auto uri(std::string&& uri) && { @@ -289,6 +295,8 @@ struct Response final { Response& operator=(const Response&) = default; Response& operator=(Response&&) = default; + ~Response() = default; + const auto& code() const { return code_; } @@ -351,6 +359,12 @@ class Client final { template class Client::_Builder final : public builder::Builder { public: + _Builder(const _Builder&) = default; + _Builder(_Builder&&) noexcept = default; + + _Builder& operator=(const _Builder&) = default; + _Builder& operator=(_Builder&&) noexcept = default; + ~_Builder() override = default; auto verify_peer(bool verify_peer) && { @@ -445,6 +459,8 @@ struct _HTTP final { interrupt_context_(&loop_, "HTTP (interrupt)"), k_(std::move(k)) {} + Continuation(const Continuation&) = delete; + Continuation(Continuation&& that) noexcept : loop_(that.loop_), request_(std::move(that.request_)), @@ -459,6 +475,9 @@ struct _HTTP final { CHECK(!handler_); } + Continuation& operator=(const Continuation&) = delete; + Continuation& operator=(Continuation&&) noexcept = delete; + ~Continuation() { CHECK(!started_ || closed_); } diff --git a/eventuals/interrupt.h b/eventuals/interrupt.h index bfb0348b8..8f4dc5849 100644 --- a/eventuals/interrupt.h +++ b/eventuals/interrupt.h @@ -29,6 +29,11 @@ class Interrupt final { CHECK(that.next_ == nullptr); } + Handler& operator=(const Handler&) = delete; + Handler& operator=(Handler&&) noexcept = delete; + + ~Handler() = default; + Interrupt& interrupt() { return *CHECK_NOTNULL(interrupt_); } diff --git a/eventuals/lazy.h b/eventuals/lazy.h index 1f3b12164..f374ff08b 100644 --- a/eventuals/lazy.h +++ b/eventuals/lazy.h @@ -18,6 +18,8 @@ struct _Lazy final { using Args = std::enable_if_t>; + _Lazy(const _Lazy&) = delete; + _Lazy(_Lazy&& that) noexcept : args_(std::move(that.args_)) { CHECK(!t_) << "'Lazy' can not be moved after using"; @@ -31,6 +33,11 @@ struct _Lazy final { _Lazy(Args&&... args) : args_(std::forward(args)...) {} + _Lazy& operator=(const _Lazy&) = delete; + _Lazy& operator=(_Lazy&&) noexcept = delete; + + ~_Lazy() = default; + T_* get() { if (!t_) { auto emplace = [this](auto&&... args) mutable { diff --git a/eventuals/lock.h b/eventuals/lock.h index 1820d25c8..fcdb79642 100644 --- a/eventuals/lock.h +++ b/eventuals/lock.h @@ -147,12 +147,17 @@ struct _Acquire final { : lock_(lock), k_(std::move(k)) {} + Continuation(const Continuation&) = delete; + Continuation(Continuation&& that) noexcept : lock_(that.lock_), k_(std::move(that.k_)) { CHECK(!waiter_.context) << "moving after starting"; } + Continuation& operator=(const Continuation&) = delete; + Continuation& operator=(Continuation&&) noexcept = delete; + ~Continuation() { CHECK(!waiter_.f) << "continuation still waiting for lock"; } @@ -573,8 +578,12 @@ struct _Wait final { f_(std::move(f)), k_(std::move(k)) {} + Continuation(const Continuation&) = delete; Continuation(Continuation&&) noexcept = default; + Continuation& operator=(const Continuation&) = delete; + Continuation& operator=(Continuation&&) noexcept = delete; + ~Continuation() { CHECK(!waiting_) << "continuation still waiting for lock"; // TODO(benh): CHECK(!waiter_.f) << "continuation still notifiable"; @@ -815,6 +824,18 @@ template class Synchronizable { public: + Synchronizable() = default; + + // Constructors and assignment operators are deleted, because + // 'Lock' class has std::atomic (which is not copyable/moveable), + // and doesn't provide its own copy/move constructors/assignment + // operators. + Synchronizable(const Synchronizable&) = delete; + Synchronizable(Synchronizable&&) noexcept = delete; + + Synchronizable& operator=(const Synchronizable&) = delete; + Synchronizable& operator=(Synchronizable&&) noexcept = delete; + virtual ~Synchronizable() = default; template diff --git a/eventuals/loop.h b/eventuals/loop.h index d11e2639a..c05ea4aec 100644 --- a/eventuals/loop.h +++ b/eventuals/loop.h @@ -84,8 +84,11 @@ struct _Loop final { stop_(std::move(stop)), k_(std::move(k)) {} + Continuation(const Continuation&) = delete; Continuation(Continuation&& that) noexcept = default; + Continuation& operator=(const Continuation&) = delete; + Continuation& operator=(Continuation&& that) noexcept { if (this == &that) { return *this; @@ -101,6 +104,8 @@ struct _Loop final { return *this; } + ~Continuation() = default; + void Begin(TypeErasedStream& stream) { stream_ = &stream; diff --git a/eventuals/pipe.h b/eventuals/pipe.h index ac4b262af..667ffbe5f 100644 --- a/eventuals/pipe.h +++ b/eventuals/pipe.h @@ -22,6 +22,12 @@ class Pipe final : public Synchronizable { Pipe() : has_values_or_closed_(&lock()) {} + Pipe(const Pipe&) = default; + Pipe(Pipe&&) noexcept = default; + + Pipe& operator=(const Pipe&) = default; + Pipe& operator=(Pipe&&) noexcept = default; + ~Pipe() override = default; [[nodiscard]] auto Write(T&& value) { diff --git a/eventuals/range.h b/eventuals/range.h index 659cbe7ad..7f6aab413 100644 --- a/eventuals/range.h +++ b/eventuals/range.h @@ -18,8 +18,12 @@ struct _Range final { step_(step), k_(std::move(k)) {} + Continuation(const Continuation&) = delete; Continuation(Continuation&& that) noexcept = default; + Continuation& operator=(const Continuation&) = delete; + Continuation& operator=(Continuation&&) noexcept = delete; + ~Continuation() override = default; void Start() { diff --git a/eventuals/scheduler.cc b/eventuals/scheduler.cc index 017bf692f..6d16540c9 100644 --- a/eventuals/scheduler.cc +++ b/eventuals/scheduler.cc @@ -12,6 +12,14 @@ namespace eventuals { class DefaultScheduler final : public Scheduler { public: + DefaultScheduler() = default; + + DefaultScheduler(const DefaultScheduler&) = default; + DefaultScheduler(DefaultScheduler&&) noexcept = default; + + DefaultScheduler& operator=(const DefaultScheduler&) = default; + DefaultScheduler& operator=(DefaultScheduler&&) noexcept = default; + ~DefaultScheduler() override = default; bool Continuable(const Context&) override { diff --git a/eventuals/stream.h b/eventuals/stream.h index 22ed7ec63..5d94d793d 100644 --- a/eventuals/stream.h +++ b/eventuals/stream.h @@ -162,8 +162,11 @@ struct _Stream final { stop_(std::move(stop)), k_(std::move(k)) {} + Continuation(const Continuation&) = delete; Continuation(Continuation&& that) noexcept = default; + Continuation& operator=(const Continuation&) = delete; + Continuation& operator=(Continuation&& that) noexcept { if (this == &that) { return *this; diff --git a/eventuals/take.h b/eventuals/take.h index 695de616e..2ad5353c8 100644 --- a/eventuals/take.h +++ b/eventuals/take.h @@ -21,7 +21,11 @@ struct _TakeLast final { : n_(n), k_(std::move(k)) {} - Continuation(Continuation&& that) noexcept = default; + Continuation(const Continuation&) = delete; + Continuation(Continuation&&) noexcept = default; + + Continuation& operator=(const Continuation&) = delete; + Continuation& operator=(Continuation&&) noexcept = delete; ~Continuation() override = default;