diff options
author | Vincent Ambo <mail@tazj.in> | 2020-08-21T03·00+0100 |
---|---|---|
committer | tazjin <mail@tazj.in> | 2020-08-23T11·58+0000 |
commit | 1cf11317cac2c11d20b2324d4283814f1351c1a3 (patch) | |
tree | 5a77610f94b0b8fd60bf64c1ca765b05ab8a6fd6 /third_party/nix/src/libutil/util.hh | |
parent | 1443298657156107704b5d9fcfa7356ee8fa8789 (diff) |
refactor(tvix/libutil): Mark single-argument constructors explicit r/1704
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 <rikingcoding@gmail.com> Reviewed-by: glittershark <grfn@gws.fyi>
Diffstat (limited to 'third_party/nix/src/libutil/util.hh')
-rw-r--r-- | third_party/nix/src/libutil/util.hh | 26 |
1 files changed, 18 insertions, 8 deletions
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 <typename... Args> - 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<void(std::future<T>)> fun) : fun(fun) {} + explicit Callback(std::function<void(std::future<T>)> fun) : fun(fun) {} Callback(Callback&& callback) : fun(std::move(callback.fun)) { auto prev = callback.done.test_and_set(); @@ -449,7 +458,8 @@ template <typename T> 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; } |