From 6756a067c254cd80a707369f5b7096f26da14e9b Mon Sep 17 00:00:00 2001 From: Lulu Date: Sun, 6 Oct 2024 22:10:40 +0200 Subject: [PATCH] Fix gcc warning -Wmissing-field-initializers Add the compile flag '-Wmissing-field-initializers' and adapt the code to fix this warning. The approach that was taken here was to add default values to the type definitions rather than specified them whenever they were missing. Change-Id: Ic223a964d67ab429e8da804c0721ba5e25d53012 --- meson.build | 1 + src/libstore/build-result.hh | 4 ++-- src/libstore/build/derivation-goal.hh | 2 +- src/libstore/build/goal.hh | 4 ++-- src/libstore/nar-accessor.cc | 4 ++-- src/libstore/path-with-outputs.hh | 2 +- src/libstore/realisation.hh | 4 ++-- src/libstore/store-api.cc | 2 +- src/libutil/processes.hh | 10 +++++----- 9 files changed, 17 insertions(+), 16 deletions(-) diff --git a/meson.build b/meson.build index fca9f4ed3..023acdf3a 100644 --- a/meson.build +++ b/meson.build @@ -486,6 +486,7 @@ add_project_arguments( # It would be nice for our headers to be idempotent instead. '-include', 'config.h', '-Wsign-compare', + '-Wmissing-field-initializers', '-Wno-deprecated-declarations', '-Wimplicit-fallthrough', '-Werror=switch', diff --git a/src/libstore/build-result.hh b/src/libstore/build-result.hh index 9634fb944..846c6c9b9 100644 --- a/src/libstore/build-result.hh +++ b/src/libstore/build-result.hh @@ -47,7 +47,7 @@ struct BuildResult * @todo This should be an entire ErrorInfo object, not just a * string, for richer information. */ - std::string errorMsg; + std::string errorMsg = {}; std::string toString() const { auto strStatus = [&]() { @@ -90,7 +90,7 @@ struct BuildResult * For derivations, a mapping from the names of the wanted outputs * to actual paths. */ - SingleDrvOutputs builtOutputs; + SingleDrvOutputs builtOutputs = {}; /** * The start/stop times of the build (or one of the rounds, if it diff --git a/src/libstore/build/derivation-goal.hh b/src/libstore/build/derivation-goal.hh index 3885afe4a..6dd58afd2 100644 --- a/src/libstore/build/derivation-goal.hh +++ b/src/libstore/build/derivation-goal.hh @@ -63,7 +63,7 @@ struct InitialOutputStatus { struct InitialOutput { bool wanted; Hash outputHash; - std::optional known; + std::optional known = {}; }; /** diff --git a/src/libstore/build/goal.hh b/src/libstore/build/goal.hh index de1c92c85..29540dcd3 100644 --- a/src/libstore/build/goal.hh +++ b/src/libstore/build/goal.hh @@ -88,8 +88,8 @@ protected: public: struct [[nodiscard]] WorkResult { ExitCode exitCode; - BuildResult result; - std::shared_ptr ex; + BuildResult result = {}; + std::shared_ptr ex = {}; bool permanentFailure = false; bool timedOut = false; bool hashMismatch = false; diff --git a/src/libstore/nar-accessor.cc b/src/libstore/nar-accessor.cc index 7600de6e7..f228004a9 100644 --- a/src/libstore/nar-accessor.cc +++ b/src/libstore/nar-accessor.cc @@ -20,10 +20,10 @@ struct NarMember file in the NAR. */ uint64_t start = 0, size = 0; - std::string target; + std::string target = {}; /* If this is a directory, all the children of the directory. */ - std::map children; + std::map children = {}; }; struct NarAccessor : public FSAccessor diff --git a/src/libstore/path-with-outputs.hh b/src/libstore/path-with-outputs.hh index 57e03252d..8e2da1908 100644 --- a/src/libstore/path-with-outputs.hh +++ b/src/libstore/path-with-outputs.hh @@ -17,7 +17,7 @@ namespace nix { struct StorePathWithOutputs { StorePath path; - std::set outputs; + std::set outputs = {}; std::string to_string(const Store & store) const; diff --git a/src/libstore/realisation.hh b/src/libstore/realisation.hh index f2b228fa0..baeb7a2c9 100644 --- a/src/libstore/realisation.hh +++ b/src/libstore/realisation.hh @@ -50,7 +50,7 @@ struct Realisation { DrvOutput id; StorePath outPath; - StringSet signatures; + StringSet signatures = {}; /** * The realisations that are required for the current one to be valid. @@ -58,7 +58,7 @@ struct Realisation { * When importing this realisation, the store will first check that all its * dependencies exist, and map to the correct output path */ - std::map dependentRealisations; + std::map dependentRealisations = {}; nlohmann::json toJSON() const; static Realisation fromJSON(const nlohmann::json& json, const std::string& whence); diff --git a/src/libstore/store-api.cc b/src/libstore/store-api.cc index d35a0e6a1..18f80eef8 100644 --- a/src/libstore/store-api.cc +++ b/src/libstore/store-api.cc @@ -829,7 +829,7 @@ StorePathSet Store::queryValidPaths(const StorePathSet & paths, SubstituteFlag m { size_t left; StorePathSet valid; - std::exception_ptr exc; + std::exception_ptr exc = {}; }; Sync state_(State{paths.size(), StorePathSet()}); diff --git a/src/libutil/processes.hh b/src/libutil/processes.hh index dc09a9ba4..dd6e2978e 100644 --- a/src/libutil/processes.hh +++ b/src/libutil/processes.hh @@ -78,11 +78,11 @@ struct RunOptions { Path program; bool searchPath = true; - Strings args; - std::optional uid; - std::optional gid; - std::optional chdir; - std::optional> environment; + Strings args = {}; + std::optional uid = {}; + std::optional gid = {}; + std::optional chdir = {}; + std::optional> environment = {}; bool captureStdout = false; bool mergeStderrToStdout = false; bool isInteractive = false;