From 35792d4531b0d54b4c1813b6f5747de38b832ec0 Mon Sep 17 00:00:00 2001 From: Keith Horton Date: Thu, 24 Oct 2024 10:03:21 -0700 Subject: [PATCH 01/10] Minor updates to move the code to more const-correct + avoiding possible string copies. --- external/CLI11.hpp | 358 ++++++++++++++++---------------- src/asm_ostream.cpp | 2 +- src/assertions.cpp | 6 +- src/crab/add_bottom.hpp | 2 +- src/crab/interval.hpp | 4 +- src/crab/linear_expression.hpp | 4 +- src/crab_utils/adapt_sgraph.hpp | 3 +- src/crab_utils/stats.cpp | 8 +- src/crab_utils/stats.hpp | 2 +- src/main/memsize_windows.hpp | 2 +- src/main/utils.hpp | 4 +- 11 files changed, 199 insertions(+), 196 deletions(-) diff --git a/external/CLI11.hpp b/external/CLI11.hpp index 8a5b4c544..766068492 100644 --- a/external/CLI11.hpp +++ b/external/CLI11.hpp @@ -421,7 +421,7 @@ CLI11_INLINE std::vector compute_win32_argv() { auto deleter = [](wchar_t **ptr) { LocalFree(ptr); }; // NOLINTBEGIN(*-avoid-c-arrays) - auto wargv = std::unique_ptr(CommandLineToArgvW(GetCommandLineW(), &argc), deleter); + const auto wargv = std::unique_ptr(CommandLineToArgvW(GetCommandLineW(), &argc), deleter); // NOLINTEND(*-avoid-c-arrays) if(wargv == nullptr) { @@ -467,7 +467,7 @@ constexpr int expected_max_vector_size{1 << 29}; CLI11_INLINE std::vector split(const std::string &s, char delim); /// Simple function to join a string -template std::string join(const T &v, std::string delim = ",") { +template std::string join(const T &v, const std::string& delim = ",") { std::ostringstream s; auto beg = std::begin(v); auto end = std::end(v); @@ -483,7 +483,7 @@ template std::string join(const T &v, std::string delim = ",") { template ::value>::type> -std::string join(const T &v, Callable func, std::string delim = ",") { +std::string join(const T &v, Callable func, const std::string& delim = ",") { std::ostringstream s; auto beg = std::begin(v); auto end = std::end(v); @@ -500,7 +500,7 @@ std::string join(const T &v, Callable func, std::string delim = ",") { } /// Join a string in reverse order -template std::string rjoin(const T &v, std::string delim = ",") { +template std::string rjoin(const T &v, const std::string& delim = ",") { std::ostringstream s; for(std::size_t start = 0; start < v.size(); start++) { if(start > 0) @@ -528,7 +528,7 @@ CLI11_INLINE std::string &rtrim(std::string &str, const std::string &filter); inline std::string &trim(std::string &str) { return ltrim(rtrim(str)); } /// Trim anything from string -inline std::string &trim(std::string &str, const std::string filter) { return ltrim(rtrim(str, filter), filter); } +inline std::string &trim(std::string &str, const std::string &filter) { return ltrim(rtrim(str, filter), filter); } /// Make a copy of the string and then trim it inline std::string trim_copy(const std::string &str) { @@ -698,25 +698,25 @@ CLI11_INLINE std::vector split(const std::string &s, char delim) { } CLI11_INLINE std::string <rim(std::string &str) { - auto it = std::find_if(str.begin(), str.end(), [](char ch) { return !std::isspace(ch, std::locale()); }); + const auto it = std::find_if(str.begin(), str.end(), [](char ch) { return !std::isspace(ch, std::locale()); }); str.erase(str.begin(), it); return str; } CLI11_INLINE std::string <rim(std::string &str, const std::string &filter) { - auto it = std::find_if(str.begin(), str.end(), [&filter](char ch) { return filter.find(ch) == std::string::npos; }); + const auto it = std::find_if(str.begin(), str.end(), [&filter](char ch) { return filter.find(ch) == std::string::npos; }); str.erase(str.begin(), it); return str; } CLI11_INLINE std::string &rtrim(std::string &str) { - auto it = std::find_if(str.rbegin(), str.rend(), [](char ch) { return !std::isspace(ch, std::locale()); }); + const auto it = std::find_if(str.rbegin(), str.rend(), [](char ch) { return !std::isspace(ch, std::locale()); }); str.erase(it.base(), str.end()); return str; } CLI11_INLINE std::string &rtrim(std::string &str, const std::string &filter) { - auto it = + const auto it = std::find_if(str.rbegin(), str.rend(), [&filter](char ch) { return filter.find(ch) == std::string::npos; }); str.erase(it.base(), str.end()); return str; @@ -793,7 +793,7 @@ CLI11_INLINE bool valid_name_string(const std::string &str) { if(str.empty() || !valid_first_char(str[0])) { return false; } - auto e = str.end(); + const auto e = str.end(); for(auto c = str.begin() + 1; c != e; ++c) if(!valid_later_char(*c)) return false; @@ -815,7 +815,7 @@ CLI11_INLINE std::string find_and_replace(std::string str, std::string from, std CLI11_INLINE void remove_default_flag_values(std::string &flags) { auto loc = flags.find_first_of('{', 2); while(loc != std::string::npos) { - auto finish = flags.find_first_of("},", loc + 1); + const auto finish = flags.find_first_of("},", loc + 1); if((finish != std::string::npos) && (flags[finish] == '}')) { flags.erase(flags.begin() + static_cast(loc), flags.begin() + static_cast(finish) + 1); @@ -826,25 +826,25 @@ CLI11_INLINE void remove_default_flag_values(std::string &flags) { } CLI11_INLINE std::ptrdiff_t -find_member(std::string name, const std::vector names, bool ignore_case, bool ignore_underscore) { +find_member(std::string name, const std::vector &names, bool ignore_case, bool ignore_underscore) { auto it = std::end(names); if(ignore_case) { if(ignore_underscore) { name = detail::to_lower(detail::remove_underscore(name)); it = std::find_if(std::begin(names), std::end(names), [&name](std::string local_name) { - return detail::to_lower(detail::remove_underscore(local_name)) == name; + return detail::to_lower(detail::remove_underscore(std::move(local_name))) == name; }); } else { name = detail::to_lower(name); it = std::find_if(std::begin(names), std::end(names), [&name](std::string local_name) { - return detail::to_lower(local_name) == name; + return detail::to_lower(std::move(local_name)) == name; }); } } else if(ignore_underscore) { name = detail::remove_underscore(name); it = std::find_if(std::begin(names), std::end(names), [&name](std::string local_name) { - return detail::remove_underscore(local_name) == name; + return detail::remove_underscore(std::move(local_name)) == name; }); } else { it = std::find(std::begin(names), std::end(names), name); @@ -865,8 +865,8 @@ CLI11_INLINE bool has_escapable_character(const std::string &str) { CLI11_INLINE std::string add_escaped_characters(const std::string &str) { std::string out; out.reserve(str.size() + 4); - for(char s : str) { - auto sloc = escapedChars.find_first_of(s); + for(const char s : str) { + const auto sloc = escapedChars.find_first_of(s); if(sloc != std::string::npos) { out.push_back('\\'); out.push_back(escapedCharsCode[sloc]); @@ -926,7 +926,7 @@ CLI11_INLINE std::string remove_escaped_characters(const std::string &str) { if(str.end() - loc < 2) { throw std::invalid_argument("invalid escape sequence " + str); } - auto ecloc = escapedCharsCode.find_first_of(*(loc + 1)); + const auto ecloc = escapedCharsCode.find_first_of(*(loc + 1)); if(ecloc != std::string::npos) { out.push_back(escapedChars[ecloc]); ++loc; @@ -938,7 +938,7 @@ CLI11_INLINE std::string remove_escaped_characters(const std::string &str) { std::uint32_t code{0}; std::uint32_t mplier{16 * 16 * 16}; for(int ii = 2; ii < 6; ++ii) { - std::uint32_t res = hexConvert(*(loc + ii)); + const std::uint32_t res = hexConvert(*(loc + ii)); if(res > 0x0F) { throw std::invalid_argument("unicode sequence must have 4 hex codes " + str); } @@ -955,7 +955,7 @@ CLI11_INLINE std::string remove_escaped_characters(const std::string &str) { std::uint32_t code{0}; std::uint32_t mplier{16 * 16 * 16 * 16 * 16 * 16 * 16}; for(int ii = 2; ii < 10; ++ii) { - std::uint32_t res = hexConvert(*(loc + ii)); + const std::uint32_t res = hexConvert(*(loc + ii)); if(res > 0x0F) { throw std::invalid_argument("unicode sequence must have 8 hex codes " + str); } @@ -992,7 +992,7 @@ CLI11_INLINE std::size_t close_string_quote(const std::string &str, std::size_t } CLI11_INLINE std::size_t close_literal_quote(const std::string &str, std::size_t start, char closure_char) { - auto loc = str.find_first_of(closure_char, start + 1); + const auto loc = str.find_first_of(closure_char, start + 1); return (loc != std::string::npos ? loc : str.size()); } @@ -1053,8 +1053,8 @@ CLI11_INLINE std::vector split_up(std::string str, char delimiter) std::vector output; while(!str.empty()) { if(bracketChars.find_first_of(str[0]) != std::string::npos) { - auto bracketLoc = bracketChars.find_first_of(str[0]); - auto end = close_sequence(str, 0, matchBracketChars[bracketLoc]); + const auto bracketLoc = bracketChars.find_first_of(str[0]); + const auto end = close_sequence(str, 0, matchBracketChars[bracketLoc]); if(end >= str.size()) { output.push_back(std::move(str)); str.clear(); @@ -1084,9 +1084,9 @@ CLI11_INLINE std::vector split_up(std::string str, char delimiter) } CLI11_INLINE std::size_t escape_detect(std::string &str, std::size_t offset) { - auto next = str[offset + 1]; + const auto next = str[offset + 1]; if((next == '\"') || (next == '\'') || (next == '`')) { - auto astart = str.find_last_of("-/ \"\'`", offset - 1); + const auto astart = str.find_last_of("-/ \"\'`", offset - 1); if(astart != std::string::npos) { if(str[astart] == ((str[offset] == '=') ? '-' : '/')) str[offset] = ' '; // interpret this as a space so the split_up works properly @@ -1099,7 +1099,7 @@ CLI11_INLINE std::string binary_escape_string(const std::string &string_to_escap // s is our escaped output string std::string escaped_string{}; // loop through all characters - for(char c : string_to_escape) { + for(const char c : string_to_escape) { // check if a given character is printable // the cast is necessary to avoid undefined behaviour if(isprint(static_cast(c)) == 0) { @@ -1130,7 +1130,7 @@ CLI11_INLINE std::string binary_escape_string(const std::string &string_to_escap } CLI11_INLINE bool is_binary_escaped_string(const std::string &escaped_string) { - size_t ssize = escaped_string.size(); + const size_t ssize = escaped_string.size(); if(escaped_string.compare(0, 3, "B\"(") == 0 && escaped_string.compare(ssize - 2, 2, ")\"") == 0) { return true; } @@ -1140,7 +1140,7 @@ CLI11_INLINE bool is_binary_escaped_string(const std::string &escaped_string) { CLI11_INLINE std::string extract_binary_string(const std::string &escaped_string) { std::size_t start{0}; std::size_t tail{0}; - size_t ssize = escaped_string.size(); + const size_t ssize = escaped_string.size(); if(escaped_string.compare(0, 3, "B\"(") == 0 && escaped_string.compare(ssize - 2, 2, ")\"") == 0) { start = 3; tail = 2; @@ -1159,11 +1159,11 @@ CLI11_INLINE std::string extract_binary_string(const std::string &escaped_string while(loc < ssize - tail) { // ssize-2 to skip )" at the end if(escaped_string[loc] == '\\' && (escaped_string[loc + 1] == 'x' || escaped_string[loc + 1] == 'X')) { - auto c1 = escaped_string[loc + 2]; - auto c2 = escaped_string[loc + 3]; + const auto c1 = escaped_string[loc + 2]; + const auto c2 = escaped_string[loc + 3]; - std::uint32_t res1 = hexConvert(c1); - std::uint32_t res2 = hexConvert(c2); + const std::uint32_t res1 = hexConvert(c1); + const std::uint32_t res2 = hexConvert(c2); if(res1 <= 0x0F && res2 <= 0x0F) { loc += 4; outstring.push_back(static_cast(res1 * 16 + res2)); @@ -1294,7 +1294,7 @@ class Error : public std::runtime_error { Error(std::string name, std::string msg, int exit_code = static_cast(ExitCodes::BaseClass)) : runtime_error(msg), actual_exit_code(exit_code), error_name(std::move(name)) {} - Error(std::string name, std::string msg, ExitCodes exit_code) : Error(name, msg, static_cast(exit_code)) {} + Error(std::string name, std::string msg, ExitCodes exit_code) : Error(std::move(name), std::move(msg), static_cast(exit_code)) {} }; // Note: Using Error::Error constructors does not work on GCC 4.7 @@ -1433,13 +1433,13 @@ class ConversionError : public ParseError { class ValidationError : public ParseError { CLI11_ERROR_DEF(ParseError, ValidationError) CLI11_ERROR_SIMPLE(ValidationError) - explicit ValidationError(std::string name, std::string msg) : ValidationError(name + ": " + msg) {} + explicit ValidationError(const std::string &name, const std::string &msg) : ValidationError(name + ": " + msg) {} }; /// Thrown when a required option is missing class RequiredError : public ParseError { CLI11_ERROR_DEF(ParseError, RequiredError) - explicit RequiredError(std::string name) : RequiredError(name + " is required", ExitCodes::RequiredError) {} + explicit RequiredError(const std::string &name) : RequiredError(name + " is required", ExitCodes::RequiredError) {} static RequiredError Subcommand(std::size_t min_subcom) { if(min_subcom == 1) { return RequiredError("A subcommand"); @@ -1475,28 +1475,28 @@ class RequiredError : public ParseError { class ArgumentMismatch : public ParseError { CLI11_ERROR_DEF(ParseError, ArgumentMismatch) CLI11_ERROR_SIMPLE(ArgumentMismatch) - ArgumentMismatch(std::string name, int expected, std::size_t received) + ArgumentMismatch(const std::string &name, int expected, std::size_t received) : ArgumentMismatch(expected > 0 ? ("Expected exactly " + std::to_string(expected) + " arguments to " + name + ", got " + std::to_string(received)) : ("Expected at least " + std::to_string(-expected) + " arguments to " + name + ", got " + std::to_string(received)), ExitCodes::ArgumentMismatch) {} - static ArgumentMismatch AtLeast(std::string name, int num, std::size_t received) { + static ArgumentMismatch AtLeast(const std::string &name, int num, std::size_t received) { return ArgumentMismatch(name + ": At least " + std::to_string(num) + " required but received " + std::to_string(received)); } - static ArgumentMismatch AtMost(std::string name, int num, std::size_t received) { + static ArgumentMismatch AtMost(const std::string &name, int num, std::size_t received) { return ArgumentMismatch(name + ": At Most " + std::to_string(num) + " required but received " + std::to_string(received)); } - static ArgumentMismatch TypedAtLeast(std::string name, int num, std::string type) { + static ArgumentMismatch TypedAtLeast(const std::string &name, int num, std::string type) { return ArgumentMismatch(name + ": " + std::to_string(num) + " required " + type + " missing"); } - static ArgumentMismatch FlagOverride(std::string name) { + static ArgumentMismatch FlagOverride(const std::string &name) { return ArgumentMismatch(name + " was given a disallowed flag override"); } - static ArgumentMismatch PartialType(std::string name, int num, std::string type) { + static ArgumentMismatch PartialType(const std::string &name, int num, std::string type) { return ArgumentMismatch(name + ": " + type + " only partially specified: " + std::to_string(num) + " required for each element"); } @@ -1505,14 +1505,14 @@ class ArgumentMismatch : public ParseError { /// Thrown when a requires option is missing class RequiresError : public ParseError { CLI11_ERROR_DEF(ParseError, RequiresError) - RequiresError(std::string curname, std::string subname) + RequiresError(const std::string &curname, const std::string &subname) : RequiresError(curname + " requires " + subname, ExitCodes::RequiresError) {} }; /// Thrown when an excludes option is present class ExcludesError : public ParseError { CLI11_ERROR_DEF(ParseError, ExcludesError) - ExcludesError(std::string curname, std::string subname) + ExcludesError(const std::string &curname, const std::string &subname) : ExcludesError(curname + " excludes " + subname, ExitCodes::ExcludesError) {} }; @@ -1536,8 +1536,8 @@ class ExtrasError : public ParseError { class ConfigError : public ParseError { CLI11_ERROR_DEF(ParseError, ConfigError) CLI11_ERROR_SIMPLE(ConfigError) - static ConfigError Extras(std::string item) { return ConfigError("INI was not able to parse " + item); } - static ConfigError NotConfigurable(std::string item) { + static ConfigError Extras(const std::string &item) { return ConfigError("INI was not able to parse " + item); } + static ConfigError NotConfigurable(const std::string &item) { return ConfigError(item + ": This option is not allowed in a configuration file"); } }; @@ -1545,7 +1545,7 @@ class ConfigError : public ParseError { /// Thrown when validation fails before parsing class InvalidError : public ParseError { CLI11_ERROR_DEF(ParseError, InvalidError) - explicit InvalidError(std::string name) + explicit InvalidError(const std::string &name) : InvalidError(name + ": Too many positional arguments with unlimited expected args", ExitCodes::InvalidError) { } }; @@ -1562,7 +1562,7 @@ class HorribleError : public ParseError { /// Thrown when counting a non-existent option class OptionNotFound : public Error { CLI11_ERROR_DEF(Error, OptionNotFound) - explicit OptionNotFound(std::string name) : OptionNotFound(name + " not found", ExitCodes::OptionNotFound) {} + explicit OptionNotFound(const std::string &name) : OptionNotFound(name + " not found", ExitCodes::OptionNotFound) {} }; #undef CLI11_ERROR_DEF @@ -2597,7 +2597,7 @@ template ::value == object_category::boolean_value, detail::enabler> = detail::dummy> bool lexical_cast(const std::string &input, T &output) { errno = 0; - auto out = to_flag_value(input); + const auto out = to_flag_value(input); if(errno == 0) { output = (out > 0); } else if(errno == ERANGE) { @@ -2639,7 +2639,7 @@ bool lexical_cast(const std::string &input, T &output) { XC x{0.0}, y{0.0}; auto str1 = input; bool worked = false; - auto nloc = str1.find_last_of("+-"); + const auto nloc = str1.find_last_of("+-"); if(nloc != std::string::npos && nloc > 0) { worked = lexical_cast(str1.substr(0, nloc), x); str1 = str1.substr(nloc); @@ -2913,7 +2913,7 @@ template = detail::dummy> bool lexical_assign(const std::string &input, AssignTo &output) { ConvertTo val{}; - bool parse_result = (!input.empty()) ? lexical_cast(input, val) : true; + const bool parse_result = (!input.empty()) ? lexical_cast(input, val) : true; if(parse_result) { output = val; } @@ -2929,7 +2929,7 @@ template < detail::enabler> = detail::dummy> bool lexical_assign(const std::string &input, AssignTo &output) { ConvertTo val{}; - bool parse_result = input.empty() ? true : lexical_cast(input, val); + const bool parse_result = input.empty() ? true : lexical_cast(input, val); if(parse_result) { output = AssignTo(val); // use () form of constructor to allow some implicit conversions } @@ -2987,7 +2987,7 @@ bool lexical_conversion(const std::vector &strings, AssignTo &outp } for(const auto &elem : strings) { typename AssignTo::value_type out; - bool retval = lexical_assign(elem, out); + const bool retval = lexical_assign(elem, out); if(!retval) { return false; } @@ -3208,8 +3208,8 @@ bool lexical_conversion(const std::vector &strings, AssignTo &outp std::vector temp; std::size_t ii{0}; std::size_t icount{0}; - std::size_t xcm{type_count::value}; - auto ii_max = strings.size(); + const std::size_t xcm{type_count::value}; + const auto ii_max = strings.size(); while(ii < ii_max) { temp.push_back(strings[ii]); ++ii; @@ -3278,10 +3278,10 @@ inline std::string sum_string_vector(const std::vector &values) { std::string output; for(const auto &arg : values) { double tv{0.0}; - auto comp = lexical_cast(arg, tv); + const auto comp = lexical_cast(arg, tv); if(!comp) { errno = 0; - auto fv = detail::to_flag_value(arg); + const auto fv = detail::to_flag_value(arg); fail = (errno != 0); if(fail) { break; @@ -3345,7 +3345,7 @@ CLI11_INLINE bool split_short(const std::string ¤t, std::string &name, std CLI11_INLINE bool split_long(const std::string ¤t, std::string &name, std::string &value) { if(current.size() > 2 && current.compare(0, 2, "--") == 0 && valid_first_char(current[2])) { - auto loc = current.find_first_of('='); + const auto loc = current.find_first_of('='); if(loc != std::string::npos) { name = current.substr(2, loc - 2); value = current.substr(loc + 1); @@ -3360,7 +3360,7 @@ CLI11_INLINE bool split_long(const std::string ¤t, std::string &name, std: CLI11_INLINE bool split_windows_style(const std::string ¤t, std::string &name, std::string &value) { if(current.size() > 1 && current[0] == '/' && valid_first_char(current[1])) { - auto loc = current.find_first_of(':'); + const auto loc = current.find_first_of(':'); if(loc != std::string::npos) { name = current.substr(1, loc - 1); value = current.substr(loc + 1); @@ -3397,7 +3397,7 @@ CLI11_INLINE std::vector> get_default_flag_v std::vector> output; output.reserve(flags.size()); for(auto &flag : flags) { - auto def_start = flag.find_first_of('{'); + const auto def_start = flag.find_first_of('{'); std::string defval = "false"; if((def_start != std::string::npos) && (flag.back() == '}')) { defval = flag.substr(def_start + 1); @@ -3865,7 +3865,7 @@ class Range : public Validator { func_ = [min_val, max_val](std::string &input) { using CLI::detail::lexical_cast; T val; - bool converted = lexical_cast(input, val); + const bool converted = lexical_cast(input, val); if((!converted) || (val < min_val || val > max_val)) { std::stringstream out; out << "Value " << input << " not in range ["; @@ -3903,7 +3903,7 @@ class Bound : public Validator { func_ = [min_val, max_val](std::string &input) { using CLI::detail::lexical_cast; T val; - bool converted = lexical_cast(input, val); + const bool converted = lexical_cast(input, val); if(!converted) { return std::string("Value ") + input + " could not be converted"; } @@ -4235,7 +4235,7 @@ class CheckedTransformer : public Validator { func_ = [mapping, tfunc, filter_fn](std::string &input) { using CLI::detail::lexical_cast; local_item_t b; - bool converted = lexical_cast(input, b); + const bool converted = lexical_cast(input, b); if(converted) { if(filter_fn) { b = filter_fn(b); @@ -4357,13 +4357,13 @@ class AsNumberWithUnit : public Validator { if(!input.empty()) { using CLI::detail::lexical_cast; - bool converted = lexical_cast(input, num); + const bool converted = lexical_cast(input, num); if(!converted) { throw ValidationError(std::string("Value ") + input + " could not be converted to " + detail::type_name()); } // perform safe multiplication - bool ok = detail::checked_multiply(num, it->second); + const bool ok = detail::checked_multiply(num, it->second); if(!ok) { throw ValidationError(detail::to_string(num) + " multiplied by " + unit + " factor would cause number overflow. Use smaller value."); @@ -4497,8 +4497,8 @@ CLI11_INLINE Validator Validator::operator&(const Validator &other) const { const std::function &f2 = other.func_; newval.func_ = [f1, f2](std::string &input) { - std::string s1 = f1(input); - std::string s2 = f2(input); + const std::string s1 = f1(input); + const std::string s2 = f2(input); if(!s1.empty() && !s2.empty()) return std::string("(") + s1 + ") AND (" + s2 + ")"; return s1 + s2; @@ -4519,8 +4519,8 @@ CLI11_INLINE Validator Validator::operator|(const Validator &other) const { const std::function &f2 = other.func_; newval.func_ = [f1, f2](std::string &input) { - std::string s1 = f1(input); - std::string s2 = f2(input); + const std::string s1 = f1(input); + const std::string s2 = f2(input); if(s1.empty() || s2.empty()) return std::string(); @@ -4535,14 +4535,14 @@ CLI11_INLINE Validator Validator::operator!() const { Validator newval; const std::function &dfunc1 = desc_function_; newval.desc_function_ = [dfunc1]() { - auto str = dfunc1(); + const auto str = dfunc1(); return (!str.empty()) ? std::string("NOT ") + str : std::string{}; }; // Give references (will make a copy in lambda function) const std::function &f1 = func_; newval.func_ = [f1, dfunc1](std::string &test) -> std::string { - std::string s1 = f1(test); + const std::string s1 = f1(test); if(s1.empty()) { return std::string("check ") + dfunc1() + " succeeded improperly"; } @@ -4560,8 +4560,8 @@ Validator::_merge_description(const Validator &val1, const Validator &val2, cons const std::function &dfunc2 = val2.desc_function_; desc_function_ = [=]() { - std::string f1 = dfunc1(); - std::string f2 = dfunc2(); + const std::string f1 = dfunc1(); + const std::string f2 = dfunc2(); if((f1.empty()) || (f2.empty())) { return f1 + f2; } @@ -4574,7 +4574,7 @@ namespace detail { #if defined CLI11_HAS_FILESYSTEM && CLI11_HAS_FILESYSTEM > 0 CLI11_INLINE path_type check_path(const char *file) noexcept { std::error_code ec; - auto stat = std::filesystem::status(to_path(file), ec); + const auto stat = std::filesystem::status(to_path(file), ec); if(ec) { return path_type::nonexistent; } @@ -4614,7 +4614,7 @@ CLI11_INLINE path_type check_path(const char *file) noexcept { CLI11_INLINE ExistingFileValidator::ExistingFileValidator() : Validator("FILE") { func_ = [](std::string &filename) { - auto path_result = check_path(filename.c_str()); + const auto path_result = check_path(filename.c_str()); if(path_result == path_type::nonexistent) { return "File does not exist: " + filename; } @@ -4627,7 +4627,7 @@ CLI11_INLINE ExistingFileValidator::ExistingFileValidator() : Validator("FILE") CLI11_INLINE ExistingDirectoryValidator::ExistingDirectoryValidator() : Validator("DIR") { func_ = [](std::string &filename) { - auto path_result = check_path(filename.c_str()); + const auto path_result = check_path(filename.c_str()); if(path_result == path_type::nonexistent) { return "Directory does not exist: " + filename; } @@ -4640,7 +4640,7 @@ CLI11_INLINE ExistingDirectoryValidator::ExistingDirectoryValidator() : Validato CLI11_INLINE ExistingPathValidator::ExistingPathValidator() : Validator("PATH(existing)") { func_ = [](std::string &filename) { - auto path_result = check_path(filename.c_str()); + const auto path_result = check_path(filename.c_str()); if(path_result == path_type::nonexistent) { return "Path does not exist: " + filename; } @@ -4650,7 +4650,7 @@ CLI11_INLINE ExistingPathValidator::ExistingPathValidator() : Validator("PATH(ex CLI11_INLINE NonexistentPathValidator::NonexistentPathValidator() : Validator("PATH(non-existing)") { func_ = [](std::string &filename) { - auto path_result = check_path(filename.c_str()); + const auto path_result = check_path(filename.c_str()); if(path_result != path_type::nonexistent) { return "Path already exists: " + filename; } @@ -4660,14 +4660,14 @@ CLI11_INLINE NonexistentPathValidator::NonexistentPathValidator() : Validator("P CLI11_INLINE IPV4Validator::IPV4Validator() : Validator("IPV4") { func_ = [](std::string &ip_addr) { - auto result = CLI::detail::split(ip_addr, '.'); + const auto result = CLI::detail::split(ip_addr, '.'); if(result.size() != 4) { return std::string("Invalid IPV4 address must have four parts (") + ip_addr + ')'; } int num = 0; for(const auto &var : result) { using CLI::detail::lexical_cast; - bool retval = lexical_cast(var, num); + const bool retval = lexical_cast(var, num); if(!retval) { return std::string("Failed parsing number (") + var + ')'; } @@ -4734,8 +4734,8 @@ CLI11_INLINE AsSizeValue::AsSizeValue(bool kb_is_1000) : AsNumberWithUnit(get_ma CLI11_INLINE std::map AsSizeValue::init_mapping(bool kb_is_1000) { std::map m; - result_t k_factor = kb_is_1000 ? 1000 : 1024; - result_t ki_factor = 1024; + const result_t k_factor = kb_is_1000 ? 1000 : 1024; + const result_t ki_factor = 1024; result_t k = 1; result_t ki = 1; m["b"] = 1; @@ -4773,7 +4773,7 @@ CLI11_INLINE std::pair split_program_name(std::string // program name if(commandline[0] == '"' || commandline[0] == '\'' || commandline[0] == '`') { bool embeddedQuote = false; - auto keyChar = commandline[0]; + const auto keyChar = commandline[0]; auto end = commandline.find_first_of(keyChar, 1); while((end != std::string::npos) && (commandline[end - 1] == '\\')) { // deal with escaped quotes end = commandline.find_first_of(keyChar, end + 1); @@ -5712,7 +5712,7 @@ class Option : public OptionBase