From e166206702c8dbd3162452cf26f368e856ac0138 Mon Sep 17 00:00:00 2001 From: Bent Bisballe Nyeng Date: Wed, 11 Dec 2024 19:15:18 +0100 Subject: More clang-tidy fixes and increase warning level (and fix them) --- src/bootstrap.cc | 6 ++++-- src/build.cc | 18 +++++++++--------- src/configure.cc | 39 ++++++++++++++++++++++----------------- src/ctor.h | 34 +++++++++++++++++----------------- src/externals_manual.cc | 2 +- src/getoptpp | 2 +- src/libctor.cc | 13 ++++++++----- src/rebuild.cc | 14 +++++++++----- src/task.cc | 15 ++++++++++----- src/task.h | 2 +- src/task_ar.cc | 14 +++++++------- src/task_cc.cc | 14 +++++++------- src/task_fn.cc | 12 ++++++------ src/task_ld.cc | 18 +++++++++--------- src/task_so.cc | 14 +++++++------- src/tasks.cc | 13 ++++++++----- src/tools.cc | 10 ++++++---- src/util.cc | 4 ++-- 18 files changed, 134 insertions(+), 110 deletions(-) (limited to 'src') diff --git a/src/bootstrap.cc b/src/bootstrap.cc index 57db670..471c844 100644 --- a/src/bootstrap.cc +++ b/src/bootstrap.cc @@ -4,6 +4,7 @@ #include #include #include +#include #define BOOTSTRAP @@ -82,9 +83,10 @@ const std::string& ctor::configuration::get(const std::string& key, const std::s int main(int argc, char* argv[]) { - if(argc > 1) + auto args = std::span(argv, static_cast(argc)); + if(args.size() > 1) { - std::cerr << "This is a minimal bootstrap version of " << argv[0] << + std::cerr << "This is a minimal bootstrap version of " << args[0] << " which doesn't support any arguments\n"; return 1; } diff --git a/src/build.cc b/src/build.cc index 3e64cca..906c3ea 100644 --- a/src/build.cc +++ b/src/build.cc @@ -142,11 +142,11 @@ std::vector> getDepTasks(std::shared_ptr task) for(const auto& dep : deps) { auto depSet = getDepTasks(dep); - for(const auto& dep : depSet) + for(const auto& dep_inner : depSet) { - if(std::find(tasks.begin(), tasks.end(), dep) == tasks.end()) + if(std::find(tasks.begin(), tasks.end(), dep_inner) == tasks.end()) { - tasks.push_back(dep); + tasks.push_back(dep_inner); } } } @@ -169,11 +169,11 @@ int build(const ctor::settings& settings, auto depSet = getDepTasks(task); std::vector> ts; - for(const auto& task : depSet) + for(const auto& task_inner : depSet) { - if(std::find(ts.begin(), ts.end(), task) == ts.end()) + if(std::find(ts.begin(), ts.end(), task_inner) == ts.end()) { - ts.push_back(task); + ts.push_back(task_inner); } } @@ -215,11 +215,11 @@ int build(const ctor::settings& settings, task_found = true; auto depSet = getDepTasks(task); - for(const auto& task : depSet) + for(const auto& task_inner : depSet) { - if(std::find(ts.begin(), ts.end(), task) == ts.end()) + if(std::find(ts.begin(), ts.end(), task_inner) == ts.end()) { - ts.push_back(task); + ts.push_back(task_inner); } } } diff --git a/src/configure.cc b/src/configure.cc index 26d3575..995e340 100644 --- a/src/configure.cc +++ b/src/configure.cc @@ -7,6 +7,7 @@ #include #include #include +#include #include @@ -321,19 +322,19 @@ int regenerateCache(ctor::settings& settings, } auto add_path_args = - [&](const std::string& name) + [&](const std::string& arg_name) { - opt.add(name + "-includedir", required_argument, key++, - "Set path to " + name + " header file.", + opt.add(arg_name + "-includedir", required_argument, key++, + "Set path to " + arg_name + " header file.", [&]() { - external_includedir[name] = optarg; + external_includedir[arg_name] = optarg; return 0; }); - opt.add(name + "-libdir", required_argument, key++, - "Set path to " + name + " libraries.", + opt.add(arg_name + "-libdir", required_argument, key++, + "Set path to " + arg_name + " libraries.", [&]() { - external_libdir[name] = optarg; + external_libdir[arg_name] = optarg; return 0; }); }; @@ -366,7 +367,7 @@ int regenerateCache(ctor::settings& settings, return 0; }); - opt.process(vargs.size(), vargs.data()); + opt.process(static_cast(vargs.size()), vargs.data()); if(host_arch_prefix.empty()) { @@ -821,12 +822,14 @@ int regenerateCache(ctor::settings& settings, int configure(const ctor::settings& global_settings, int argc, char* argv[]) { + auto args_span = std::span(argv, static_cast(argc)); + ctor::settings settings{global_settings}; std::vector args; - for(int i = 2; i < argc; ++i) // skip command and the first 'configure' arg + for(std::size_t i = 2; i < args_span.size(); ++i) // skip command and the first 'configure' arg { - args.emplace_back(argv[i]); + args.emplace_back(args_span[i]); } std::map env; @@ -860,7 +863,7 @@ int configure(const ctor::settings& global_settings, int argc, char* argv[]) env["PATH"] = path_env; } - auto ret = regenerateCache(settings, argv[0], args, env); + auto ret = regenerateCache(settings, args_span[0], args, env); if(ret != 0) { return ret; @@ -873,19 +876,21 @@ int configure(const ctor::settings& global_settings, int argc, char* argv[]) int reconfigure(const ctor::settings& global_settings, int argc, char* argv[]) { + auto args_span = std::span(argv, static_cast(argc)); + ctor::settings settings{global_settings}; bool no_rerun{false}; std::vector args; - for(int i = 2; i < argc; ++i) // skip executable name and 'reconfigure' arg + for(std::size_t i = 2; i < args_span.size(); ++i) // skip executable name and 'reconfigure' arg { - if(i == 2 && std::string(argv[i]) == "--no-rerun") + if(i == 2 && std::string(args_span[i]) == "--no-rerun") { no_rerun = true; continue; } - args.emplace_back(argv[i]); + args.emplace_back(args_span[i]); } const auto& cfg = ctor::get_configuration(); @@ -895,14 +900,14 @@ int reconfigure(const ctor::settings& global_settings, int argc, char* argv[]) { std::cout << e.first << "=\"" << e.second << "\" "; } - std::cout << argv[0] << " configure "; + std::cout << args_span[0] << " configure "; for(const auto& arg : cfg.args) { std::cout << arg << " "; } std::cout << "\n"; - auto ret = regenerateCache(settings, argv[0], cfg.args, cfg.env); + auto ret = regenerateCache(settings, args_span[0], cfg.args, cfg.env); if(ret != 0) { return ret; @@ -915,5 +920,5 @@ int reconfigure(const ctor::settings& global_settings, int argc, char* argv[]) return 0; // this was originally invoked by configure, don't loop } - return execute(settings, argv[0], args); + return execute(settings, args_span[0], args); } diff --git a/src/ctor.h b/src/ctor.h index 1de4aec..e0e2bef 100644 --- a/src/ctor.h +++ b/src/ctor.h @@ -63,20 +63,20 @@ enum class toolchain struct source { - constexpr source(const char* file) : file(file) {} // convenience ctor + source(const char* file_) : file(file_) {} // convenience ctor - constexpr source(std::string_view file) : source(file, ctor::language::automatic) {} - constexpr source(std::string_view file, ctor::language lang) : file(file), language(lang) {} + source(std::string_view file_) : source(file_, ctor::language::automatic) {} + source(std::string_view file_, ctor::language lang_) : file(file_), language(lang_) {} - constexpr source(std::string_view file, std::string_view output) : file(file), output(output) {} - constexpr source(std::string_view file, ctor::language lang, std::string_view output) : file(file), language(lang), output(output) {} + source(std::string_view file_, std::string_view output_) : file(file_), output(output_) {} + source(std::string_view file_, ctor::language lang_, std::string_view output_) : file(file_), language(lang_), output(output_) {} - constexpr source(ctor::toolchain toolchain, std::string_view file) : file(file), toolchain(toolchain) {} - constexpr source(ctor::toolchain toolchain, std::string_view file, ctor::language lang) : file(file), toolchain(toolchain), language(lang) {} + source(ctor::toolchain toolchain_, std::string_view file_) : file(file_), toolchain(toolchain_) {} + source(ctor::toolchain toolchain_, std::string_view file_, ctor::language lang_) : file(file_), toolchain(toolchain_), language(lang_) {} - constexpr source(ctor::toolchain toolchain, std::string_view file, std::string_view output) : file(file), toolchain(toolchain), output(output) {} + source(ctor::toolchain toolchain_, std::string_view file_, std::string_view output_) : file(file_), toolchain(toolchain_), output(output_) {} - constexpr source(ctor::toolchain toolchain, std::string_view file, ctor::language lang, std::string_view output) : file(file), toolchain(toolchain), language(lang), output(output) {} + source(ctor::toolchain toolchain_, std::string_view file_, ctor::language lang_, std::string_view output_) : file(file_), toolchain(toolchain_), language(lang_), output(output_) {} std::string file; ctor::toolchain toolchain{ctor::toolchain::any}; @@ -156,17 +156,17 @@ template class flag { public: - flag(const std::string& str); + flag(std::string_view str); flag(const char* str); - flag(T opt) : opt(opt) {} - flag(T opt, const std::string& arg) : opt(opt), arg(arg) {} - flag(T opt, const char* arg) : opt(opt), arg(arg) {} - flag(ctor::toolchain toolchain, T opt) : toolchain(toolchain), opt(opt) {} - flag(ctor::toolchain toolchain, T opt, const char* arg) : toolchain(toolchain), opt(opt), arg(arg) {} - flag(ctor::toolchain toolchain, T opt, const std::string& arg) : toolchain(toolchain), opt(opt), arg(arg) {} + flag(T opt_) : opt(opt_) {} + flag(T opt_, std::string_view arg_) : opt(opt_), arg(arg_) {} + flag(T opt_, const char* arg_) : opt(opt_), arg(arg_) {} + flag(ctor::toolchain toolchain_, T opt_) : toolchain(toolchain_), opt(opt_) {} + flag(ctor::toolchain toolchain_, T opt_, const char* arg_) : toolchain(toolchain_), opt(opt_), arg(arg_) {} + flag(ctor::toolchain toolchain_, T opt_, std::string_view arg_) : toolchain(toolchain_), opt(opt_), arg(arg_) {} ctor::toolchain toolchain{ctor::toolchain::any}; - T opt; + T opt{}; std::string arg; }; diff --git a/src/externals_manual.cc b/src/externals_manual.cc index 2434d71..0563a5e 100644 --- a/src/externals_manual.cc +++ b/src/externals_manual.cc @@ -13,7 +13,7 @@ extern std::map external_includedir; extern std::map external_libdir; -int resolv(const ctor::settings& settings, const ctor::external_configuration& config, +int resolv([[maybe_unused]]const ctor::settings& settings, const ctor::external_configuration& config, const ctor::external_manual& ext, ctor::flags& flags) { flags = ext.flags; diff --git a/src/getoptpp b/src/getoptpp index 9ff20ef..5aba943 160000 --- a/src/getoptpp +++ b/src/getoptpp @@ -1 +1 @@ -Subproject commit 9ff20ef857429619267e3f156a4f81ad9e1eb8c1 +Subproject commit 5aba94355ec638c6f8612f86be309ed684979ae3 diff --git a/src/libctor.cc b/src/libctor.cc index 9be14b2..b1fbaea 100644 --- a/src/libctor.cc +++ b/src/libctor.cc @@ -15,6 +15,7 @@ #include #include #include +#include #include @@ -27,6 +28,8 @@ int main(int argc, char* argv[]) { + auto args = std::span(argv, static_cast(argc)); + ctor::settings settings{}; const auto& c = ctor::get_configuration(); @@ -34,12 +37,12 @@ int main(int argc, char* argv[]) settings.parallel_processes = std::max(1u, std::thread::hardware_concurrency()) * 2 - 1; - if(argc > 1 && std::string(argv[1]) == "configure") + if(args.size() > 1 && std::string(args[1]) == "configure") { return configure(settings, argc, argv); } - if(argc > 1 && std::string(argv[1]) == "reconfigure") + if(args.size() > 1 && std::string(args[1]) == "reconfigure") { return reconfigure(settings, argc, argv); } @@ -64,7 +67,8 @@ int main(int argc, char* argv[]) [&]() { try { - settings.parallel_processes = std::stoi(optarg); + settings.parallel_processes = + static_cast(std::stoi(optarg)); } catch(...) { @@ -156,7 +160,7 @@ int main(int argc, char* argv[]) opt.add("help", no_argument, 'h', "Print this help text.", [&]() { - std::cout << "Usage: " << argv[0] << " [options] [target] ...\n"; + std::cout << "Usage: " << args[0] << " [options] [target] ...\n"; std::cout << R"_( where target can be either: configure - run configuration step (cannot be used with other targets). @@ -270,7 +274,6 @@ Options: if(print_configure_db) { no_default_build = true; - const auto& c = ctor::get_configuration(); for(const auto& config : c.tools) { std::cout << config.first << ": " << config.second << "\n"; diff --git a/src/rebuild.cc b/src/rebuild.cc index c176744..1db5e83 100644 --- a/src/rebuild.cc +++ b/src/rebuild.cc @@ -8,6 +8,7 @@ #include #include #include +#include #include "configure.h" #include "ctor.h" @@ -105,7 +106,7 @@ int unreg(const char* location) } } - return found; + return static_cast(found); } std::array externalConfigFiles; @@ -150,6 +151,8 @@ bool contains(const std::vector& sources, const std::string& file) bool recompileCheck(const ctor::settings& global_settings, int argc, char* argv[], bool relaunch_allowed) { + auto args_span = std::span(argv, static_cast(argc)); + using namespace std::string_literals; if(global_settings.verbose > 1) @@ -187,7 +190,7 @@ bool recompileCheck(const ctor::settings& global_settings, int argc, char* argv[ { std::filesystem::path buildfile = settings.builddir; - std::filesystem::path currentfile = argv[0]; + std::filesystem::path currentfile = args_span[0]; config.target = std::filesystem::relative(currentfile, buildfile).string(); } @@ -267,11 +270,12 @@ bool recompileCheck(const ctor::settings& global_settings, int argc, char* argv[ { args.emplace_back("--no-rerun"); } - for(int i = 1; i < argc; ++i) + for(std::size_t i = 1; i < args_span.size(); ++i) { - args.emplace_back(argv[i]); + args.emplace_back(args_span[i]); } - auto ret = execute(settings, argv[0], args); + + auto ret = execute(settings, args_span[0], args); //if(ret != 0) { exit(ret); diff --git a/src/task.cc b/src/task.cc index 680dbf8..a9c0fee 100644 --- a/src/task.cc +++ b/src/task.cc @@ -8,12 +8,12 @@ #include #include -Task::Task(const ctor::build_configuration& config, const ctor::settings& settings, - std::string sourceDir) - : config(config) +Task::Task(const ctor::build_configuration& config_, const ctor::settings& settings_, + std::string sourceDir_) + : config(config_) , output_system(config.system) - , settings(settings) - , sourceDir(std::move(sourceDir)) + , settings(settings_) + , sourceDir(std::move(sourceDir_)) { } @@ -145,6 +145,7 @@ std::string Task::compiler() const case ctor::output_system::build: return c.get(ctor::cfg::build_cc, "/usr/bin/gcc"); } + break; case ctor::language::cpp: switch(outputSystem()) { @@ -153,11 +154,15 @@ std::string Task::compiler() const case ctor::output_system::build: return c.get(ctor::cfg::build_cxx, "/usr/bin/g++"); } + break; default: std::cerr << "Unknown CC target type\n"; exit(1); break; } + + std::cerr << "Unhandled compiler!\n"; + exit(1); } std::vector> Task::getDependsTasks() diff --git a/src/task.h b/src/task.h index 0303b2e..e930a54 100644 --- a/src/task.h +++ b/src/task.h @@ -28,7 +28,7 @@ public: virtual ~Task() = default; int registerDepTasks(const std::vector>& tasks); - virtual int registerDepTasksInner(const std::vector>& tasks) { return 0; } + virtual int registerDepTasksInner([[maybe_unused]]const std::vector>& tasks) { return 0; } bool operator==(const std::string& dep); diff --git a/src/task_ar.cc b/src/task_ar.cc index 25a49a2..b16a2f9 100644 --- a/src/task_ar.cc +++ b/src/task_ar.cc @@ -11,16 +11,16 @@ #include "util.h" #include "tools.h" -TaskAR::TaskAR(const ctor::build_configuration& config, - const ctor::settings& settings, +TaskAR::TaskAR(const ctor::build_configuration& config_, + const ctor::settings& settings_, const std::string& target, const std::vector& objects, - const std::string& sourceDir) - : Task(config, settings, sourceDir) + const std::string& sourceDir_) + : Task(config_, settings_, sourceDir_) , _targetFile(target) - , config(config) - , settings(settings) - , sourceDir(sourceDir) + , config(config_) + , settings(settings_) + , sourceDir(sourceDir_) { target_type = ctor::target_type::static_library; output_system = config.system; diff --git a/src/task_cc.cc b/src/task_cc.cc index 49aef78..e1f3023 100644 --- a/src/task_cc.cc +++ b/src/task_cc.cc @@ -13,13 +13,13 @@ #include "util.h" #include "tools.h" -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) +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 /= source.file; diff --git a/src/task_fn.cc b/src/task_fn.cc index 0ad697a..2fa0ad6 100644 --- a/src/task_fn.cc +++ b/src/task_fn.cc @@ -11,12 +11,12 @@ #include "execute.h" #include "util.h" -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) +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 /= source.file; diff --git a/src/task_ld.cc b/src/task_ld.cc index aad6947..c8cd1ea 100644 --- a/src/task_ld.cc +++ b/src/task_ld.cc @@ -11,17 +11,17 @@ #include "util.h" #include "tools.h" -TaskLD::TaskLD(const ctor::build_configuration& config, - const ctor::settings& settings, +TaskLD::TaskLD(const ctor::build_configuration& config_, + const ctor::settings& settings_, const std::string& target, const std::vector& objects, - const std::string& sourceDir, - bool is_self) - : Task(config, settings, sourceDir) - , config(config) - , settings(settings) - , sourceDir(sourceDir) - , is_self(is_self) + const std::string& sourceDir_, + bool is_self_) + : Task(config_, settings_, sourceDir_) + , config(config_) + , settings(settings_) + , sourceDir(sourceDir_) + , is_self(is_self_) { target_type = config.type; output_system = config.system; diff --git a/src/task_so.cc b/src/task_so.cc index 5453100..75b5f3c 100644 --- a/src/task_so.cc +++ b/src/task_so.cc @@ -11,15 +11,15 @@ #include "util.h" #include "tools.h" -TaskSO::TaskSO(const ctor::build_configuration& config, - const ctor::settings& settings, +TaskSO::TaskSO(const ctor::build_configuration& config_, + const ctor::settings& settings_, const std::string& target, const std::vector& objects, - const std::string& sourceDir) - : Task(config, settings, sourceDir) - , config(config) - , settings(settings) - , sourceDir(sourceDir) + const std::string& sourceDir_) + : Task(config_, settings_, sourceDir_) + , config(config_) + , settings(settings_) + , sourceDir(sourceDir_) { std::filesystem::path base = sourceDir; diff --git a/src/tasks.cc b/src/tasks.cc index 0e59097..2f9e47a 100644 --- a/src/tasks.cc +++ b/src/tasks.cc @@ -8,6 +8,7 @@ #include #include #include +#include #include "ctor.h" #include "task.h" @@ -24,20 +25,22 @@ const std::deque& getTargets(const ctor::settings& settings, bool resolve_externals) { + auto config_files = std::span(configFiles).subspan(0, numConfigFiles); + static bool initialised{false}; static std::deque targets; if(!initialised) { const auto& externals = ctor::get_configuration().externals; - for(std::size_t i = 0; i < numConfigFiles; ++i) + for(const auto& config_file : config_files) { std::string path = - std::filesystem::path(configFiles[i].file).parent_path().string(); + std::filesystem::path(config_file.file).parent_path().string(); if(settings.verbose > 1) { - std::cout << configFiles[i].file << " in path " << path << "\n"; + std::cout << config_file.file << " in path " << path << "\n"; } - auto configs = configFiles[i].cb(settings); + auto configs = config_file.cb(settings); for(auto& config : configs) { if(resolve_externals) @@ -167,7 +170,7 @@ std::vector> taskFactory(const ctor::build_configuration& return tasks; } -std::shared_ptr getNextTask(const std::vector>& allTasks, +std::shared_ptr getNextTask([[maybe_unused]]const std::vector>& allTasks, std::vector>& dirtyTasks) { for(auto dirtyTask = dirtyTasks.begin(); diff --git a/src/tools.cc b/src/tools.cc index be94794..394a91c 100644 --- a/src/tools.cc +++ b/src/tools.cc @@ -175,10 +175,11 @@ std::string get_arch(ctor::output_system system) std::string arch; while(!feof(pipe)) { - char buf[1024]; - if(fgets(buf, sizeof(buf), pipe) != nullptr) + constexpr auto buffer_size{1024}; + std::array buf{}; + if(fgets(buf.data(), buf.size(), pipe) != nullptr) { - arch = buf; + arch = buf.data(); if(arch.starts_with("Target:")) { break; @@ -195,7 +196,8 @@ std::string get_arch(ctor::output_system system) } // Remove 'Target: ' prefix - arch = arch.substr(8); + constexpr auto prefix_length{8}; + arch = arch.substr(prefix_length); return arch; } diff --git a/src/util.cc b/src/util.cc index 76d380b..73b158d 100644 --- a/src/util.cc +++ b/src/util.cc @@ -22,10 +22,10 @@ std::string readFile(const std::string& fileName) std::ifstream::pos_type fileSize = ifs.tellg(); ifs.seekg(0, std::ios::beg); - std::vector bytes(fileSize); + std::vector bytes(static_cast(fileSize)); ifs.read(bytes.data(), fileSize); - return std::string(bytes.data(), fileSize); + return {bytes.data(), static_cast(fileSize)}; } std::vector readDeps(const std::string& depFile) -- cgit v1.2.3