diff --git a/src/libexpr/eval.cc b/src/libexpr/eval.cc index ab3f7b3ff..6bcde9283 100644 --- a/src/libexpr/eval.cc +++ b/src/libexpr/eval.cc @@ -741,6 +741,11 @@ public: inDebugger = true; } + DebuggerGuard(DebuggerGuard &&) = delete; + DebuggerGuard(const DebuggerGuard &) = delete; + DebuggerGuard & operator=(DebuggerGuard &&) = delete; + DebuggerGuard & operator=(const DebuggerGuard &) = delete; + ~DebuggerGuard() { inDebugger = false; diff --git a/src/libexpr/include/nix/expr/attr-set.hh b/src/libexpr/include/nix/expr/attr-set.hh index f57302c42..4d3821fed 100644 --- a/src/libexpr/include/nix/expr/attr-set.hh +++ b/src/libexpr/include/nix/expr/attr-set.hh @@ -107,6 +107,8 @@ private: Bindings & operator=(const Bindings &) = delete; Bindings & operator=(Bindings &&) = delete; + ~Bindings() = default; + friend class BindingsBuilder; /** diff --git a/src/libexpr/include/nix/expr/value.hh b/src/libexpr/include/nix/expr/value.hh index 004dcc43f..6f533b73b 100644 --- a/src/libexpr/include/nix/expr/value.hh +++ b/src/libexpr/include/nix/expr/value.hh @@ -164,8 +164,6 @@ public: Value ** elems; ListBuilder(EvalMemory & mem, size_t size); - // NOTE: Can be noexcept because we are just copying integral values and - // raw pointers. ListBuilder(ListBuilder && x) noexcept : size(x.size) , inlineElems{x.inlineElems[0], x.inlineElems[1]} @@ -173,6 +171,11 @@ public: { } + ListBuilder(const ListBuilder &) = delete; + ListBuilder & operator=(ListBuilder &&) = delete; + ListBuilder & operator=(const ListBuilder &) = delete; + ~ListBuilder() = default; + Value *& operator[](size_t n) { return elems[n]; diff --git a/src/libstore/include/nix/store/pathlocks.hh b/src/libstore/include/nix/store/pathlocks.hh index 7e27bec4c..dbb75a676 100644 --- a/src/libstore/include/nix/store/pathlocks.hh +++ b/src/libstore/include/nix/store/pathlocks.hh @@ -33,6 +33,22 @@ private: public: PathLocks(); PathLocks(const std::set & paths, const std::string & waitMsg = ""); + + PathLocks(PathLocks && other) noexcept + : fds(std::exchange(other.fds, {})) + , deletePaths(other.deletePaths) + { + } + + PathLocks & operator=(PathLocks && other) noexcept + { + fds = std::exchange(other.fds, {}); + deletePaths = other.deletePaths; + return *this; + } + + PathLocks(const PathLocks &) = delete; + PathLocks & operator=(const PathLocks &) = delete; bool lockPaths(const std::set & _paths, const std::string & waitMsg = "", bool wait = true); ~PathLocks(); void unlock(); @@ -45,6 +61,10 @@ struct FdLock bool acquired = false; FdLock(Descriptor desc, LockType lockType, bool wait, std::string_view waitMsg); + FdLock(const FdLock &) = delete; + FdLock & operator=(const FdLock &) = delete; + FdLock(FdLock &&) = delete; + FdLock & operator=(FdLock &&) = delete; ~FdLock() { diff --git a/src/libutil/freebsd/include/nix/util/freebsd-jail.hh b/src/libutil/freebsd/include/nix/util/freebsd-jail.hh index 33a86a398..cfab3c2a6 100644 --- a/src/libutil/freebsd/include/nix/util/freebsd-jail.hh +++ b/src/libutil/freebsd/include/nix/util/freebsd-jail.hh @@ -11,6 +11,24 @@ class AutoRemoveJail bool del; public: AutoRemoveJail(int jid); + AutoRemoveJail(const AutoRemoveJail &) = delete; + AutoRemoveJail & operator=(const AutoRemoveJail &) = delete; + + AutoRemoveJail(AutoRemoveJail && other) noexcept + : jid(other.jid) + , del(other.del) + { + other.cancel(); + } + + AutoRemoveJail & operator=(AutoRemoveJail && other) noexcept + { + jid = other.jid; + del = other.del; + other.cancel(); + return *this; + } + AutoRemoveJail(); ~AutoRemoveJail(); void cancel(); diff --git a/src/libutil/include/nix/util/file-system.hh b/src/libutil/include/nix/util/file-system.hh index 7d88939e3..ba409fac8 100644 --- a/src/libutil/include/nix/util/file-system.hh +++ b/src/libutil/include/nix/util/file-system.hh @@ -480,8 +480,23 @@ class AutoUnmount Path path; bool del; public: - AutoUnmount(Path &); AutoUnmount(); + AutoUnmount(Path &); + AutoUnmount(const AutoUnmount &) = delete; + + AutoUnmount(AutoUnmount && other) noexcept + : path(std::move(other.path)) + , del(std::exchange(other.del, false)) + { + } + + AutoUnmount & operator=(AutoUnmount && other) noexcept + { + path = std::move(other.path); + del = std::exchange(other.del, false); + return *this; + } + ~AutoUnmount(); void cancel(); }; diff --git a/src/libutil/include/nix/util/serialise.hh b/src/libutil/include/nix/util/serialise.hh index 6322156aa..be26ff23d 100644 --- a/src/libutil/include/nix/util/serialise.hh +++ b/src/libutil/include/nix/util/serialise.hh @@ -159,6 +159,8 @@ struct FdSink : BufferedSink } FdSink(FdSink &&) = default; + FdSink(const FdSink &) = delete; + FdSink & operator=(const FdSink &) = delete; FdSink & operator=(FdSink && s) { @@ -200,8 +202,10 @@ struct FdSource : BufferedSource, RestartableSource } FdSource(FdSource &&) = default; - FdSource & operator=(FdSource && s) = default; + FdSource(const FdSource &) = delete; + FdSource & operator=(const FdSource & s) = delete; + ~FdSource() = default; bool good() override; void restart() override; @@ -452,6 +456,11 @@ struct LambdaSink : Sink { } + LambdaSink(LambdaSink &&) = delete; + LambdaSink(const LambdaSink &) = delete; + LambdaSink & operator=(LambdaSink &&) = delete; + LambdaSink & operator=(const LambdaSink &) = delete; + ~LambdaSink() { cleanupFun(); @@ -628,6 +637,11 @@ struct FramedSource : Source { } + FramedSource(FramedSource &&) = delete; + FramedSource(const FramedSource &) = delete; + FramedSource & operator=(FramedSource &&) = delete; + FramedSource & operator=(const FramedSource &) = delete; + ~FramedSource() { try { @@ -685,6 +699,11 @@ struct FramedSink : nix::BufferedSink { } + FramedSink(FramedSink &&) = delete; + FramedSink(const FramedSink &) = delete; + FramedSink & operator=(FramedSink &&) = delete; + FramedSink & operator=(const FramedSink &) = delete; + ~FramedSink() { try { diff --git a/src/libutil/include/nix/util/sync.hh b/src/libutil/include/nix/util/sync.hh index 3a41d1bd8..ad640410a 100644 --- a/src/libutil/include/nix/util/sync.hh +++ b/src/libutil/include/nix/util/sync.hh @@ -69,13 +69,10 @@ public: { } public: - Lock(Lock && l) - : s(l.s) - { - unreachable(); - } - + Lock(Lock && l) = delete; Lock(const Lock & l) = delete; + Lock & operator=(Lock && l) = delete; + Lock & operator=(const Lock & l) = delete; ~Lock() {} @@ -110,6 +107,8 @@ public: struct WriteLock : Lock { + using Lock::Lock; + T * operator->() { return &WriteLock::s->data; @@ -131,6 +130,8 @@ public: struct ReadLock : Lock { + using Lock::Lock; + const T * operator->() { return &ReadLock::s->data; diff --git a/src/libutil/include/nix/util/util.hh b/src/libutil/include/nix/util/util.hh index 7556663cd..adbb9e19a 100644 --- a/src/libutil/include/nix/util/util.hh +++ b/src/libutil/include/nix/util/util.hh @@ -384,6 +384,11 @@ struct MaintainCount counter += delta; } + MaintainCount(MaintainCount &&) = delete; + MaintainCount(const MaintainCount &) = delete; + MaintainCount & operator=(MaintainCount &&) = delete; + MaintainCount & operator=(const MaintainCount &) = delete; + ~MaintainCount() { counter -= delta; diff --git a/src/libutil/include/nix/util/xml-writer.hh b/src/libutil/include/nix/util/xml-writer.hh index 8d084ad11..e0561f0ab 100644 --- a/src/libutil/include/nix/util/xml-writer.hh +++ b/src/libutil/include/nix/util/xml-writer.hh @@ -50,6 +50,11 @@ public: writer.openElement(name, attrs); } + XMLOpenElement(XMLOpenElement &&) = delete; + XMLOpenElement(const XMLOpenElement &) = delete; + XMLOpenElement & operator=(XMLOpenElement &&) = delete; + XMLOpenElement & operator=(const XMLOpenElement &) = delete; + ~XMLOpenElement() { writer.closeElement(); diff --git a/src/libutil/unix/include/nix/util/monitor-fd.hh b/src/libutil/unix/include/nix/util/monitor-fd.hh index b87bf5ca4..de2338ef0 100644 --- a/src/libutil/unix/include/nix/util/monitor-fd.hh +++ b/src/libutil/unix/include/nix/util/monitor-fd.hh @@ -27,6 +27,10 @@ private: public: MonitorFdHup(int fd); + MonitorFdHup(MonitorFdHup &&) = delete; + MonitorFdHup(const MonitorFdHup &) = delete; + MonitorFdHup & operator=(MonitorFdHup &&) = delete; + MonitorFdHup & operator=(const MonitorFdHup &) = delete; ~MonitorFdHup() { diff --git a/src/libutil/unix/signals.cc b/src/libutil/unix/signals.cc index de441492a..deff40276 100644 --- a/src/libutil/unix/signals.cc +++ b/src/libutil/unix/signals.cc @@ -141,6 +141,16 @@ struct InterruptCallbackImpl : InterruptCallback { InterruptCallbacks::Token token; + InterruptCallbackImpl(InterruptCallbacks::Token token) + : token(token) + { + } + + InterruptCallbackImpl(InterruptCallbackImpl &&) = delete; + InterruptCallbackImpl(const InterruptCallbackImpl &) = delete; + InterruptCallbackImpl & operator=(InterruptCallbackImpl &&) = delete; + InterruptCallbackImpl & operator=(const InterruptCallbackImpl &) = delete; + ~InterruptCallbackImpl() override { auto interruptCallbacks(_interruptCallbacks.lock()); @@ -153,11 +163,7 @@ std::unique_ptr createInterruptCallback(std::function auto interruptCallbacks(_interruptCallbacks.lock()); auto token = interruptCallbacks->nextToken++; interruptCallbacks->callbacks.emplace(token, callback); - - std::unique_ptr res{new InterruptCallbackImpl{}}; - res->token = token; - - return std::unique_ptr(res.release()); + return std::make_unique(token); } } // namespace nix