From 4f3422c58ed4fc14b222cd474843affb9cc509c4 Mon Sep 17 00:00:00 2001 From: Bent Bisballe Nyeng Date: Mon, 9 Dec 2024 20:02:33 +0100 Subject: Various clang-tidy fixes. --- src/bootstrap.cc | 25 +++++++++++++++---------- src/build.cc | 12 +++++------- src/configure.cc | 4 ++-- src/execute.cc | 4 ++-- src/externals_manual.cc | 6 +++--- src/libctor.cc | 8 ++++---- src/rebuild.cc | 23 ++++++++++++----------- src/task.cc | 5 +++-- src/task.h | 2 +- src/task_ar.cc | 4 ++-- src/task_cc.cc | 2 +- src/task_fn.cc | 2 +- src/task_ld.cc | 2 +- src/task_so.cc | 2 +- 14 files changed, 53 insertions(+), 48 deletions(-) diff --git a/src/bootstrap.cc b/src/bootstrap.cc index 55bd3e0..45ecad4 100644 --- a/src/bootstrap.cc +++ b/src/bootstrap.cc @@ -42,33 +42,38 @@ bool ctor::configuration::has(const std::string& key) const const std::string& ctor::configuration::get(const std::string& key, const std::string& default_value) const { - if(key == ctor::cfg::build_cxx && std::getenv("CXX")) + auto cxx_env = std::getenv("CXX"); + if(key == ctor::cfg::build_cxx && cxx_env) { - static std::string s = std::getenv("CXX"); + static std::string s = cxx_env; return s; } - if(key == ctor::cfg::build_cc && std::getenv("CC")) + auto cc_env = std::getenv("CC"); + if(key == ctor::cfg::build_cc && cc_env) { - static std::string s = std::getenv("CC"); + static std::string s = cc_env; return s; } - if(key == ctor::cfg::build_ld && std::getenv("LD")) + auto ld_env = std::getenv("LD"); + if(key == ctor::cfg::build_ld && ld_env) { - static std::string s = std::getenv("LD"); + static std::string s = ld_env; return s; } - if(key == ctor::cfg::build_ar && std::getenv("AR")) + auto ar_env = std::getenv("AR"); + if(key == ctor::cfg::build_ar && ar_env) { - static std::string s = std::getenv("AR"); + static std::string s = ar_env; return s; } - if(key == ctor::cfg::builddir && std::getenv("BUILDDIR")) + auto builddir_env = std::getenv("BUILDDIR"); + if(key == ctor::cfg::builddir && builddir_env) { - static std::string s = std::getenv("BUILDDIR"); + static std::string s = builddir_env; return s; } diff --git a/src/build.cc b/src/build.cc index ea65656..ca02514 100644 --- a/src/build.cc +++ b/src/build.cc @@ -114,17 +114,15 @@ int build(const ctor::settings& settings, } } - for(auto process = processes.begin(); - process != processes.end(); - ++process) + for(auto& process : processes) { - if(process->valid() == false) + if(process.valid() == false) { continue; } - process->wait(); - auto ret = process->get(); - if(ret != 0) + process.wait(); + auto ret = process.get(); + if (ret != 0) { return ret; } diff --git a/src/configure.cc b/src/configure.cc index 4b2fbf0..a0e107a 100644 --- a/src/configure.cc +++ b/src/configure.cc @@ -826,7 +826,7 @@ int configure(const ctor::settings& global_settings, int argc, char* argv[]) std::vector args; for(int i = 2; i < argc; ++i) // skip command and the first 'configure' arg { - args.push_back(argv[i]); + args.emplace_back(argv[i]); } std::map env; @@ -885,7 +885,7 @@ int reconfigure(const ctor::settings& global_settings, int argc, char* argv[]) no_rerun = true; continue; } - args.push_back(argv[i]); + args.emplace_back(argv[i]); } const auto& cfg = ctor::get_configuration(); diff --git a/src/execute.cc b/src/execute.cc index 94a3d73..cbae899 100644 --- a/src/execute.cc +++ b/src/execute.cc @@ -46,7 +46,7 @@ public: int parent_waitpid(pid_t pid) { - int status; + int status{}; if(waitpid(pid, &status, 0) != pid) { @@ -104,7 +104,7 @@ int execute(const ctor::settings& settings, for(auto current = environ; *current; ++current) { - venv.push_back(*current); + venv.emplace_back(*current); } Env penv(venv); diff --git a/src/externals_manual.cc b/src/externals_manual.cc index 3b96263..2434d71 100644 --- a/src/externals_manual.cc +++ b/src/externals_manual.cc @@ -21,14 +21,14 @@ int resolv(const ctor::settings& settings, const ctor::external_configuration& c auto inc = external_includedir.find(config.name); if(inc != external_includedir.end()) { - flags.cflags.push_back({ctor::c_opt::include_path, inc->second}); - flags.cxxflags.push_back({ctor::cxx_opt::include_path, inc->second}); + flags.cflags.emplace_back(ctor::c_opt::include_path, inc->second); + flags.cxxflags.emplace_back(ctor::cxx_opt::include_path, inc->second); } auto lib = external_libdir.find(config.name); if(lib != external_libdir.end()) { - flags.ldflags.push_back({ctor::ld_opt::library_path, lib->second}); + flags.ldflags.emplace_back(ctor::ld_opt::library_path, lib->second); } return 0; diff --git a/src/libctor.cc b/src/libctor.cc index 3eb6c6f..9be14b2 100644 --- a/src/libctor.cc +++ b/src/libctor.cc @@ -100,7 +100,7 @@ int main(int argc, char* argv[]) "Add specified file to the build configurations.", [&]() { no_relaunch = true; - add_files.push_back(optarg); + add_files.emplace_back(optarg); return 0; }); @@ -108,7 +108,7 @@ int main(int argc, char* argv[]) "Remove specified file from the build configurations.", [&]() { no_relaunch = true; - remove_files.push_back(optarg); + remove_files.emplace_back(optarg); return 0; }); @@ -187,12 +187,12 @@ Options: std::vector files; for(std::size_t i = 0; i < numConfigFiles; ++i) { - files.push_back(configFiles[i].file); + files.emplace_back(configFiles[i].file); } for(std::size_t i = 0; i < numExternalConfigFiles; ++i) { - files.push_back(externalConfigFiles[i].file); + files.emplace_back(externalConfigFiles[i].file); } std::sort(files.begin(), files.end()); diff --git a/src/rebuild.cc b/src/rebuild.cc index 460bbfb..c176744 100644 --- a/src/rebuild.cc +++ b/src/rebuild.cc @@ -163,22 +163,23 @@ bool recompileCheck(const ctor::settings& global_settings, int argc, char* argv[ config.name = "ctor"; config.system = ctor::output_system::build; - config.flags.cxxflags.push_back({ctor::cxx_opt::optimization, "3"}); - config.flags.cxxflags.push_back({ctor::cxx_opt::cpp_std, "c++20"}); + config.flags.cxxflags.emplace_back(ctor::cxx_opt::optimization, "3"); + config.flags.cxxflags.emplace_back(ctor::cxx_opt::cpp_std, "c++20"); const auto& c = ctor::get_configuration(); if(c.has(ctor::cfg::ctor_includedir)) { - config.flags.cxxflags.push_back({ctor::cxx_opt::include_path, - c.get(ctor::cfg::ctor_includedir)}); + config.flags.cxxflags.emplace_back(ctor::cxx_opt::include_path, + c.get(ctor::cfg::ctor_includedir)); } if(c.has(ctor::cfg::ctor_libdir)) { - config.flags.ldflags.push_back({ctor::ld_opt::library_path, c.get(ctor::cfg::ctor_libdir)}); + config.flags.ldflags.emplace_back(ctor::ld_opt::library_path, + c.get(ctor::cfg::ctor_libdir)); } - config.flags.ldflags.push_back({ctor::ld_opt::link, "ctor"}); - config.flags.ldflags.push_back({ctor::ld_opt::strip}); - config.flags.ldflags.push_back({ctor::ld_opt::threads}); + config.flags.ldflags.emplace_back(ctor::ld_opt::link, "ctor"); + config.flags.ldflags.emplace_back(ctor::ld_opt::strip); + config.flags.ldflags.emplace_back(ctor::ld_opt::threads); ctor::settings settings{global_settings}; settings.verbose = -1; // Make check completely silent. @@ -261,14 +262,14 @@ bool recompileCheck(const ctor::settings& global_settings, int argc, char* argv[ if(reconfigure) { std::vector args; - args.push_back("reconfigure"); + args.emplace_back("reconfigure"); if(!relaunch_allowed) { - args.push_back("--no-rerun"); + args.emplace_back("--no-rerun"); } for(int i = 1; i < argc; ++i) { - args.push_back(argv[i]); + args.emplace_back(argv[i]); } auto ret = execute(settings, argv[0], args); //if(ret != 0) diff --git a/src/task.cc b/src/task.cc index 7813235..680dbf8 100644 --- a/src/task.cc +++ b/src/task.cc @@ -6,13 +6,14 @@ #include #include #include +#include Task::Task(const ctor::build_configuration& config, const ctor::settings& settings, - const std::string& sourceDir) + std::string sourceDir) : config(config) , output_system(config.system) , settings(settings) - , sourceDir(sourceDir) + , sourceDir(std::move(sourceDir)) { } diff --git a/src/task.h b/src/task.h index 6fe1686..0303b2e 100644 --- a/src/task.h +++ b/src/task.h @@ -24,7 +24,7 @@ class Task { public: Task(const ctor::build_configuration& config, const ctor::settings& settings, - const std::string& sourceDir); + std::string sourceDir); virtual ~Task() = default; int registerDepTasks(const std::vector>& tasks); diff --git a/src/task_ar.cc b/src/task_ar.cc index b15ad4e..25a49a2 100644 --- a/src/task_ar.cc +++ b/src/task_ar.cc @@ -17,6 +17,7 @@ TaskAR::TaskAR(const ctor::build_configuration& config, const std::vector& objects, const std::string& sourceDir) : Task(config, settings, sourceDir) + , _targetFile(target) , config(config) , settings(settings) , sourceDir(sourceDir) @@ -24,7 +25,6 @@ TaskAR::TaskAR(const ctor::build_configuration& config, target_type = ctor::target_type::static_library; output_system = config.system; - _targetFile = target; auto toolchain = getToolChain(config.system); _targetFile = extension(toolchain, target_type, config.system, _targetFile); for(const auto& object : objects) @@ -36,7 +36,7 @@ TaskAR::TaskAR(const ctor::build_configuration& config, for(const auto& dep : config.depends) { - depFiles.push_back(dep); + depFiles.emplace_back(dep); } flagsFile = std::filesystem::path(settings.builddir) / cleanUp(sourceDir) / targetFile().stem(); diff --git a/src/task_cc.cc b/src/task_cc.cc index dabeefa..49aef78 100644 --- a/src/task_cc.cc +++ b/src/task_cc.cc @@ -16,12 +16,12 @@ TaskCC::TaskCC(const ctor::build_configuration& config, const ctor::settings& settings, const std::string& sourceDir, const ctor::source& source) : Task(config, settings, sourceDir) + , sourceFile(sourceDir) , config(config) , settings(settings) , sourceDir(sourceDir) , _source(source) { - sourceFile = sourceDir; sourceFile /= source.file; std::filesystem::path base = sourceFile.parent_path(); diff --git a/src/task_fn.cc b/src/task_fn.cc index b11ff15..0ad697a 100644 --- a/src/task_fn.cc +++ b/src/task_fn.cc @@ -14,10 +14,10 @@ TaskFn::TaskFn(const ctor::build_configuration& config, const ctor::settings& settings, const std::string& sourceDir, const ctor::source& source) : Task(config, settings, sourceDir) + , sourceFile(sourceDir) , config(config) , settings(settings) { - sourceFile = sourceDir; sourceFile /= source.file; std::filesystem::create_directories(std::filesystem::path(settings.builddir) / sourceFile.parent_path()); diff --git a/src/task_ld.cc b/src/task_ld.cc index dc1006a..aad6947 100644 --- a/src/task_ld.cc +++ b/src/task_ld.cc @@ -43,7 +43,7 @@ TaskLD::TaskLD(const ctor::build_configuration& config, for(const auto& dep : config.depends) { - depFiles.push_back(dep); + depFiles.emplace_back(dep); } flagsFile = std::filesystem::path(settings.builddir) / cleanUp(sourceDir) / targetFile().stem(); diff --git a/src/task_so.cc b/src/task_so.cc index 25839c5..5453100 100644 --- a/src/task_so.cc +++ b/src/task_so.cc @@ -38,7 +38,7 @@ TaskSO::TaskSO(const ctor::build_configuration& config, for(const auto& dep : config.depends) { - depFiles.push_back(dep); + depFiles.emplace_back(dep); } flagsFile = std::filesystem::path(settings.builddir) / cleanUp(sourceDir) / targetFile().stem(); -- cgit v1.2.3