From 43e79f443469c55ef4d3a43ce1e455d6eafcd26c 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 The approach that was taken here was to add default values to the type definitions rather than specify them whenever they are missing. Now the only remaining warning is '-Wunused-parameter' which @jade said is usually counterproductive and that we can just disable it: https://git.lix.systems/lix-project/lix/issues/456#issuecomment-6617 So this change adds the flags '-Wall', '-Wextra' and '-Wno-unused-parameter', so that all warnings are enabled except for '-Wunused-parameter'. Change-Id: Ic223a964d67ab429e8da804c0721ba5e25d53012 --- meson.build | 5 ++--- src/libexpr/parser/state.hh | 2 +- 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/error.hh | 6 +++--- src/libutil/processes.hh | 10 +++++----- 11 files changed, 22 insertions(+), 23 deletions(-) diff --git a/meson.build b/meson.build index fca9f4ed3..c7fe647ce 100644 --- a/meson.build +++ b/meson.build @@ -52,8 +52,7 @@ project('lix', 'cpp', 'rust', default_options : [ 'cpp_std=c++2a', 'rust_std=2021', - # TODO(Qyriad): increase the warning level - 'warning_level=1', + 'warning_level=2', 'debug=true', 'optimization=2', 'errorlogs=true', # Please print logs for tests that fail @@ -485,7 +484,7 @@ add_project_arguments( # TODO(Qyriad): Yes this is how the autoconf+Make system did it. # It would be nice for our headers to be idempotent instead. '-include', 'config.h', - '-Wsign-compare', + '-Wno-unused-parameter', '-Wno-deprecated-declarations', '-Wimplicit-fallthrough', '-Werror=switch', diff --git a/src/libexpr/parser/state.hh b/src/libexpr/parser/state.hh index 1d57e2f5f..3b9b90b94 100644 --- a/src/libexpr/parser/state.hh +++ b/src/libexpr/parser/state.hh @@ -9,7 +9,7 @@ namespace nix::parser { struct StringToken { std::string_view s; - bool hasIndentation; + bool hasIndentation = false; operator std::string_view() const { return s; } }; 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/error.hh b/src/libutil/error.hh index 4eff2c2bc..885a2b218 100644 --- a/src/libutil/error.hh +++ b/src/libutil/error.hh @@ -70,17 +70,17 @@ inline bool operator<=(const Trace& lhs, const Trace& rhs); inline bool operator>=(const Trace& lhs, const Trace& rhs); struct ErrorInfo { - Verbosity level; + Verbosity level = Verbosity::lvlError; HintFmt msg; std::shared_ptr pos; - std::list traces; + std::list traces = {}; /** * Exit status. */ unsigned int status = 1; - Suggestions suggestions; + Suggestions suggestions = {}; static std::optional programName; }; 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;