diff --git a/.clang-tidy b/.clang-tidy index 87f6d0404..77ee39cb8 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -16,6 +16,8 @@ Checks: - -bugprone-unchecked-optional-access # many warnings, seems like a questionable lint - -bugprone-branch-clone + # extremely noisy before clang 19: https://github.com/llvm/llvm-project/issues/93959 + - -bugprone-multi-level-implicit-pointer-conversion # all thrown exceptions must derive from std::exception - hicpp-exception-baseclass # capturing async lambdas are dangerous @@ -33,3 +35,4 @@ Checks: CheckOptions: bugprone-reserved-identifier.AllowedIdentifiers: '__asan_default_options' + bugprone-unused-return-value.AllowCastToVoid: true diff --git a/lix/legacy/nix-env.cc b/lix/legacy/nix-env.cc index 58353fc32..3862288f4 100644 --- a/lix/legacy/nix-env.cc +++ b/lix/legacy/nix-env.cc @@ -1326,7 +1326,7 @@ static void opSwitchGeneration(Globals & globals, Strings opFlags, Strings opArg throw UsageError("exactly one argument expected"); if (auto dstGen = string2Int(opArgs.front())) - switchGeneration(globals.profile, *dstGen, globals.dryRun); + switchGeneration(globals.profile, dstGen, globals.dryRun); else throw UsageError("expected a generation number"); } diff --git a/lix/libexpr/attr-path.cc b/lix/libexpr/attr-path.cc index a3d5d1ca5..134f9e16c 100644 --- a/lix/libexpr/attr-path.cc +++ b/lix/libexpr/attr-path.cc @@ -120,7 +120,6 @@ std::pair findPackageFilename(EvalState & state, Value & v try { auto colon = fn.rfind(':'); if (colon == std::string::npos) fail(); - std::string filename(fn, 0, colon); auto lineno = std::stoi(std::string(fn, colon + 1, std::string::npos)); return {CanonPath(fn.substr(0, colon)), lineno}; } catch (std::invalid_argument & e) { diff --git a/lix/libfetchers/fetchers.cc b/lix/libfetchers/fetchers.cc index 828fd191f..125c8772a 100644 --- a/lix/libfetchers/fetchers.cc +++ b/lix/libfetchers/fetchers.cc @@ -263,9 +263,7 @@ std::optional Input::getNarHash() const std::optional Input::getRef() const { - if (auto s = maybeGetStrAttr(attrs, "ref")) - return *s; - return {}; + return maybeGetStrAttr(attrs, "ref"); } std::optional Input::getRev() const @@ -286,16 +284,12 @@ std::optional Input::getRev() const std::optional Input::getRevCount() const { - if (auto n = maybeGetIntAttr(attrs, "revCount")) - return *n; - return {}; + return maybeGetIntAttr(attrs, "revCount"); } std::optional Input::getLastModified() const { - if (auto n = maybeGetIntAttr(attrs, "lastModified")) - return *n; - return {}; + return maybeGetIntAttr(attrs, "lastModified"); } ParsedURL InputScheme::toURL(const Input & input) const diff --git a/lix/libfetchers/git.cc b/lix/libfetchers/git.cc index cb4f243db..7d352b65c 100644 --- a/lix/libfetchers/git.cc +++ b/lix/libfetchers/git.cc @@ -132,7 +132,7 @@ std::optional readHeadCached(const std::string & actualUrl) // This function must behave the same way, so we return the expired // cached ref here. warn("could not get HEAD ref for repository '%s'; using expired cached ref '%s'", actualUrl, *cachedRef); - return *cachedRef; + return cachedRef; } return std::nullopt; diff --git a/lix/libstore/build/derivation-goal.cc b/lix/libstore/build/derivation-goal.cc index 5ea5e50c2..a50aa4553 100644 --- a/lix/libstore/build/derivation-goal.cc +++ b/lix/libstore/build/derivation-goal.cc @@ -1286,7 +1286,7 @@ HookReply DerivationGoal::tryBuildHook() hook->toHook.reset(); /* Create the log file and pipe. */ - Path logFile = openLogFile(); + openLogFile(); builderOutFD = &hook->builderOut; return HookReply::Accept{handleChildOutput()}; diff --git a/lix/libstore/build/local-derivation-goal.cc b/lix/libstore/build/local-derivation-goal.cc index 89ebc816d..794b85031 100644 --- a/lix/libstore/build/local-derivation-goal.cc +++ b/lix/libstore/build/local-derivation-goal.cc @@ -707,7 +707,7 @@ kj::Promise> LocalDerivationGoal::startBuilder() printMsg(lvlVomit, "setting builder env variable '%1%'='%2%'", i.first, i.second); /* Create the log file. */ - Path logFile = openLogFile(); + openLogFile(); /* Create a pseudoterminal to get the output of the builder. */ builderOutPTY = AutoCloseFD{posix_openpt(O_RDWR | O_NOCTTY)}; diff --git a/lix/libstore/common-protocol.cc b/lix/libstore/common-protocol.cc index d0385c9c6..c244b7a54 100644 --- a/lix/libstore/common-protocol.cc +++ b/lix/libstore/common-protocol.cc @@ -93,7 +93,7 @@ WireFormatGenerator CommonProto::Serialise>::write { return [](std::string s) -> WireFormatGenerator { co_yield s; - }(caOpt ? renderContentAddress(*caOpt) : ""); + }(caOpt ? renderContentAddress(caOpt) : ""); } } diff --git a/lix/libstore/export-import.cc b/lix/libstore/export-import.cc index 50305464f..a79c1300a 100644 --- a/lix/libstore/export-import.cc +++ b/lix/libstore/export-import.cc @@ -13,14 +13,9 @@ void Store::exportPaths(const StorePathSet & paths, Sink & sink) auto sorted = topoSortPaths(paths); std::reverse(sorted.begin(), sorted.end()); - std::string doneLabel("paths exported"); - //logger->incExpected(doneLabel, sorted.size()); - for (auto & path : sorted) { - //Activity act(*logger, lvlInfo, "exporting path '%s'", path); sink << 1; exportPath(path, sink); - //logger->incProgress(doneLabel); } sink << 0; diff --git a/lix/libstore/nar-accessor.cc b/lix/libstore/nar-accessor.cc index d409a0019..9239ef697 100644 --- a/lix/libstore/nar-accessor.cc +++ b/lix/libstore/nar-accessor.cc @@ -145,7 +145,6 @@ struct NarAccessor : public FSAccessor NarMember * find(const Path & path) { - Path canon = path == "" ? "" : canonPath(path); NarMember * current = &root; auto end = path.end(); for (auto it = path.begin(); it != end; ) { diff --git a/lix/libstore/nar-info.cc b/lix/libstore/nar-info.cc index fc11d4c8d..21166d56d 100644 --- a/lix/libstore/nar-info.cc +++ b/lix/libstore/nar-info.cc @@ -120,7 +120,7 @@ std::string NarInfo::to_string(const Store & store) const res += "Sig: " + sig + "\n"; if (ca) - res += "CA: " + renderContentAddress(*ca) + "\n"; + res += "CA: " + renderContentAddress(ca) + "\n"; return res; } diff --git a/lix/libstore/store-api.cc b/lix/libstore/store-api.cc index 08cde6e99..e7e030a55 100644 --- a/lix/libstore/store-api.cc +++ b/lix/libstore/store-api.cc @@ -1365,8 +1365,7 @@ std::optional Store::getBuildDerivationPath(const StorePath & path) if (!path.isDerivation()) { try { auto info = queryPathInfo(path); - if (!info->deriver) return std::nullopt; - return *info->deriver; + return info->deriver; } catch (InvalidPath &) { return std::nullopt; } diff --git a/lix/libutil/hilite.cc b/lix/libutil/hilite.cc index 43acb9cd5..1b5d9b916 100644 --- a/lix/libutil/hilite.cc +++ b/lix/libutil/hilite.cc @@ -25,7 +25,7 @@ std::string hiliteMatches( out.append(s.substr(last_end, m.position() - last_end)); // Merge continous matches ssize_t end = start + m.length(); - while (++it != matches.end() && (*it).position() <= end) { + for (++it; it != matches.end() && (*it).position() <= end; ++it) { auto n = *it; ssize_t nend = start + (n.position() - start + n.length()); if (nend > end) diff --git a/lix/libutil/serialise.cc b/lix/libutil/serialise.cc index 10310c561..a8b10a590 100644 --- a/lix/libutil/serialise.cc +++ b/lix/libutil/serialise.cc @@ -116,7 +116,6 @@ void Source::operator () (char * data, size_t len) void Source::drainInto(Sink & sink) { - std::string s; std::array buf; while (true) { size_t n; @@ -297,7 +296,7 @@ Error readError(Source & source) auto type = readString(source); assert(type == "Error"); auto level = (Verbosity) readInt(source); - auto name = readString(source); // removed + readString(source); // removed (name) auto msg = readString(source); ErrorInfo info { .level = level, diff --git a/lix/libutil/terminal.cc b/lix/libutil/terminal.cc index e436fde24..6b24ade47 100644 --- a/lix/libutil/terminal.cc +++ b/lix/libutil/terminal.cc @@ -34,7 +34,7 @@ bool shouldANSI(StandardOutputStream fileno) // FIXME(jade): replace with TerminalCodeEater. wowie this is evil code. std::string filterANSIEscapes(std::string_view s, bool filterAll, unsigned int width, bool eatTabs) { - std::string t, e; + std::string t; size_t w = 0; auto i = s.begin(); diff --git a/lix/nix/bundle.cc b/lix/nix/bundle.cc index bf2ba002e..0407f7ce1 100644 --- a/lix/nix/bundle.cc +++ b/lix/nix/bundle.cc @@ -117,8 +117,6 @@ struct CmdBundle : InstallableCommand }, }); - auto outPathS = store->printStorePath(outPath); - if (!outLink) { auto * attr = vRes->attrs->get(evaluator->s.name); if (!attr) diff --git a/lix/nix/path-info.cc b/lix/nix/path-info.cc index 8848c169d..f9902fb35 100644 --- a/lix/nix/path-info.cc +++ b/lix/nix/path-info.cc @@ -118,7 +118,7 @@ struct CmdPathInfo : StorePathsCommand, MixJSON std::cout << '\t'; Strings ss; if (info->ultimate) ss.push_back("ultimate"); - if (info->ca) ss.push_back("ca:" + renderContentAddress(*info->ca)); + if (info->ca) ss.push_back("ca:" + renderContentAddress(info->ca)); for (auto & sig : info->sigs) ss.push_back(sig); std::cout << concatStringsSep(" ", ss); } diff --git a/lix/nix/search.cc b/lix/nix/search.cc index 58c8a3890..d51f53f09 100644 --- a/lix/nix/search.cc +++ b/lix/nix/search.cc @@ -159,7 +159,6 @@ struct CmdSearch : InstallableCommand, MixJSON {"description", description}, }; } else { - auto name2 = hiliteMatches(name.name, nameMatches, ANSI_GREEN, "\e[0;2m"); if (results > 1) logger->cout(""); logger->cout( "* %s%s", diff --git a/lix/nix/sigs.cc b/lix/nix/sigs.cc index 9a63e19cf..ae729172e 100644 --- a/lix/nix/sigs.cc +++ b/lix/nix/sigs.cc @@ -40,13 +40,9 @@ struct CmdCopySigs : StorePathsCommand ThreadPool pool{"CopySigs pool"}; - std::string doneLabel = "done"; std::atomic added{0}; - //logger->setExpected(doneLabel, storePaths.size()); - auto doPath = [&](const Path & storePathS) { - //Activity act(*logger, lvlInfo, "getting signatures for '%s'", storePath); checkInterrupt(); @@ -78,8 +74,6 @@ struct CmdCopySigs : StorePathsCommand store->addSignatures(storePath, newSigs); added += newSigs.size(); } - - //logger->incProgress(doneLabel); }; for (auto & storePath : storePaths)