From 1cf11317cac2c11d20b2324d4283814f1351c1a3 Mon Sep 17 00:00:00 2001 From: Vincent Ambo Date: Fri, 21 Aug 2020 04:00:55 +0100 Subject: refactor(tvix/libutil): Mark single-argument constructors explicit This is the clang-tidy lint 'google-explicit-constructor'. There's a whole bunch of breakage that was introduced by this, and we had to opt out a few types of this (esp. the string formatting crap). In some cases minor other changes have been done to keep the code working, instead of converting between types (e.g. an explicit comparison operator implementation for nix::Pid). Change-Id: I12e1ca51a6bc2c882dba81a2526b9729d26988e7 Reviewed-on: https://cl.tvl.fyi/c/depot/+/1832 Tested-by: BuildkiteCI Reviewed-by: kanepyork Reviewed-by: glittershark --- third_party/nix/src/libutil/util.hh | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) (limited to 'third_party/nix/src/libutil/util.hh') diff --git a/third_party/nix/src/libutil/util.hh b/third_party/nix/src/libutil/util.hh index b5383b6e71f8..b6d726b46c01 100644 --- a/third_party/nix/src/libutil/util.hh +++ b/third_party/nix/src/libutil/util.hh @@ -167,11 +167,11 @@ class AutoDelete { public: AutoDelete(); - AutoDelete(Path p, bool recursive = true); + explicit AutoDelete(Path p, bool recursive = true); ~AutoDelete(); void cancel(); void reset(const Path& p, bool recursive = true); - operator Path() const { return path; } + explicit operator Path() const { return path; } }; class AutoCloseFD { @@ -180,7 +180,7 @@ class AutoCloseFD { public: AutoCloseFD(); - AutoCloseFD(int fd); + explicit AutoCloseFD(int fd); AutoCloseFD(const AutoCloseFD& fd) = delete; AutoCloseFD(AutoCloseFD&& that); ~AutoCloseFD(); @@ -210,16 +210,24 @@ class Pid { public: Pid(); - Pid(pid_t pid); + explicit Pid(pid_t pid); ~Pid(); void operator=(pid_t pid); - operator pid_t(); + explicit operator pid_t(); int kill(); int wait(); void setSeparatePG(bool separatePG); void setKillSignal(int signal); pid_t release(); + + friend bool operator==(const Pid& lhs, const Pid& rhs) { + return lhs.pid == rhs.pid; + } + + friend bool operator!=(const Pid& lhs, const Pid& rhs) { + return !(lhs == rhs); + } }; /* Kill all processes running under the specified uid by sending them @@ -275,7 +283,8 @@ class ExecError : public Error { int status; template - ExecError(int status, Args... args) : Error(args...), status(status) {} + explicit ExecError(int status, Args... args) + : Error(args...), status(status) {} }; /* Convert a list of strings to a null-terminated vector of char @@ -378,7 +387,7 @@ class Callback { std::atomic_flag done = ATOMIC_FLAG_INIT; public: - Callback(std::function)> fun) : fun(fun) {} + explicit Callback(std::function)> fun) : fun(fun) {} Callback(Callback&& callback) : fun(std::move(callback.fun)) { auto prev = callback.done.test_and_set(); @@ -449,7 +458,8 @@ template struct MaintainCount { T& counter; long delta; - MaintainCount(T& counter, long delta = 1) : counter(counter), delta(delta) { + explicit MaintainCount(T& counter, long delta = 1) + : counter(counter), delta(delta) { counter += delta; } ~MaintainCount() { counter -= delta; } -- cgit 1.4.1