refactor(3p/nix): Make all single-argument constructors explicit

Implicit constructors can be confusing, especially in a codebase that
is already as unintentionally obfuscated as this one.

https://google.github.io/styleguide/cppguide.html#Explicit_Constructors
This commit is contained in:
Vincent Ambo 2020-05-19 22:02:23 +01:00
parent 3908732181
commit 88f337588c
12 changed files with 31 additions and 31 deletions

View file

@ -133,7 +133,7 @@ class Goal : public std::enable_shared_from_this<Goal> {
/* Whether the goal is finished. */
ExitCode exitCode;
Goal(Worker& worker) : worker(worker) {
explicit Goal(Worker& worker) : worker(worker) {
nrFailed = nrNoSubstituters = nrIncompleteClosure = 0;
exitCode = ecBusy;
}
@ -264,7 +264,7 @@ class Worker {
it answers with "decline-permanently", we don't try again. */
bool tryBuildHook = true;
Worker(LocalStore& store);
explicit Worker(LocalStore& store);
~Worker();
/* Make a goal (with caching). */
@ -823,7 +823,7 @@ class DerivationGoal : public Goal {
struct ChrootPath {
Path source;
bool optional;
ChrootPath(Path source = "", bool optional = false)
explicit ChrootPath(Path source = "", bool optional = false)
: source(source), optional(optional) {}
};
typedef map<Path, ChrootPath>
@ -2037,12 +2037,12 @@ void DerivationGoal::startBuilder() {
}
size_t p = i.find('=');
if (p == string::npos) {
dirsInChroot[i] = {i, optional};
dirsInChroot[i] = ChrootPath(i, optional);
} else {
dirsInChroot[string(i, 0, p)] = {string(i, p + 1), optional};
dirsInChroot[string(i, 0, p)] = ChrootPath(string(i, p + 1), optional);
}
}
dirsInChroot[tmpDirInSandbox] = tmpDir;
dirsInChroot[tmpDirInSandbox] = ChrootPath(tmpDir);
/* Add the closure of store paths to the chroot. */
PathSet closure;
@ -2058,7 +2058,7 @@ void DerivationGoal::startBuilder() {
}
}
for (auto& i : closure) {
dirsInChroot[i] = i;
dirsInChroot[i] = ChrootPath(i);
}
PathSet allowedPaths = settings.allowedImpureHostPrefixes;
@ -2088,7 +2088,7 @@ void DerivationGoal::startBuilder() {
drvPath % i);
}
dirsInChroot[i] = i;
dirsInChroot[i] = ChrootPath(i);
}
#if __linux__
@ -2170,7 +2170,7 @@ void DerivationGoal::startBuilder() {
throw SysError(format("getting attributes of path '%1%'") % i);
}
if (S_ISDIR(st.st_mode)) {
dirsInChroot[i] = r;
dirsInChroot[i] = ChrootPath(r);
} else {
Path p = chrootRootDir + i;
DLOG(INFO) << "linking '" << p << "' to '" << r << "'";
@ -2264,9 +2264,9 @@ void DerivationGoal::startBuilder() {
} else {
auto p = line.find('=');
if (p == string::npos) {
dirsInChroot[line] = line;
dirsInChroot[line] = ChrootPath(line);
} else {
dirsInChroot[string(line, 0, p)] = string(line, p + 1);
dirsInChroot[string(line, 0, p)] = ChrootPath(string(line, p + 1));
}
}
}

View file

@ -9,7 +9,7 @@ namespace nix {
struct HashAndWriteSink : Sink {
Sink& writeSink;
HashSink hashSink;
HashAndWriteSink(Sink& writeSink)
explicit HashAndWriteSink(Sink& writeSink)
: writeSink(writeSink), hashSink(htSHA256) {}
virtual void operator()(const unsigned char* data, size_t len) {
writeSink(data, len);

View file

@ -505,7 +505,7 @@ struct LocalStore::GCState {
unsigned long long bytesInvalidated;
bool moveToTrash = true;
bool shouldDelete;
GCState(GCResults& results_) : results(results_), bytesInvalidated(0) {}
explicit GCState(GCResults& results_) : results(results_), bytesInvalidated(0) {}
};
bool LocalStore::isActiveTempFile(const GCState& state, const Path& path,

View file

@ -12,7 +12,7 @@ LocalFSStore::LocalFSStore(const Params& params) : Store(params) {}
struct LocalStoreAccessor : public FSAccessor {
ref<LocalFSStore> store;
LocalStoreAccessor(ref<LocalFSStore> store) : store(store) {}
explicit LocalStoreAccessor(ref<LocalFSStore> store) : store(store) {}
Path toRealPath(const Path& path) {
Path storePath = store->toStorePath(path);

View file

@ -151,7 +151,7 @@ void Store::queryMissing(const PathSet& targets, PathSet& willBuild_,
size_t left;
bool done = false;
PathSet outPaths;
DrvState(size_t left) : left(left) {}
explicit DrvState(size_t left) : left(left) {}
};
Sync<State> state_(State{PathSet(), unknown_, willSubstitute_, willBuild_,

View file

@ -93,7 +93,7 @@ struct NarAccessor : public FSAccessor {
}
};
NarAccessor(ref<const std::string> nar) : nar(nar) {
explicit NarAccessor(ref<const std::string> nar) : nar(nar) {
NarIndexer indexer(*this, *nar);
parseDump(indexer, indexer);
}

View file

@ -27,7 +27,7 @@ static void makeWritable(const Path& path) {
struct MakeReadOnly {
Path path;
MakeReadOnly(const Path& path) : path(path) {}
explicit MakeReadOnly(const Path& path) : path(path) {}
~MakeReadOnly() {
try {
/* This will make the path read-only. */

View file

@ -215,7 +215,7 @@ struct ConnectionHandle {
Pool<RemoteStore::Connection>::Handle handle;
bool daemonException = false;
ConnectionHandle(Pool<RemoteStore::Connection>::Handle&& handle)
explicit ConnectionHandle(Pool<RemoteStore::Connection>::Handle&& handle)
: handle(std::move(handle)) {}
ConnectionHandle(ConnectionHandle&& h) : handle(std::move(h.handle)) {}