diff --git a/.clang-tidy b/.clang-tidy index 5d737ee3f..508250276 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -1,5 +1,5 @@ --- -Checks: 'clang-diagnostic-*,clang-analyzer-*,cert-*,performance-*,portability-*' +Checks: 'clang-diagnostic-*,clang-analyzer-*,cert-*,performance-*,portability-*,modernize-use-auto' WarningsAsErrors: '' HeaderFilterRegex: '' AnalyzeTemporaryDtors: false @@ -9,5 +9,7 @@ CheckOptions: value: 'L;LL;LU;LLU' - key: cert-oop54-cpp.WarnOnlyIfThisHasSuspiciousField value: '0' + - key: modernize-use-auto.RemoveStars + value: '1' ... diff --git a/src/builtin_printf.cpp b/src/builtin_printf.cpp index bda9d974b..8b46a20ba 100644 --- a/src/builtin_printf.cpp +++ b/src/builtin_printf.cpp @@ -488,7 +488,7 @@ void builtin_printf_state_t::print_direc(const wchar_t *start, size_t length, wc switch (conversion) { case L'd': case L'i': { - intmax_t arg = string_to_scalar_type(argument, this); + auto arg = string_to_scalar_type(argument, this); if (!have_field_width) { if (!have_precision) this->append_format_output(fmt.c_str(), arg); @@ -506,7 +506,7 @@ void builtin_printf_state_t::print_direc(const wchar_t *start, size_t length, wc case L'u': case L'x': case L'X': { - uintmax_t arg = string_to_scalar_type(argument, this); + auto arg = string_to_scalar_type(argument, this); if (!have_field_width) { if (!have_precision) this->append_format_output(fmt.c_str(), arg); @@ -528,7 +528,7 @@ void builtin_printf_state_t::print_direc(const wchar_t *start, size_t length, wc case L'F': case L'g': case L'G': { - long double arg = string_to_scalar_type(argument, this); + auto arg = string_to_scalar_type(argument, this); if (!have_field_width) { if (!have_precision) { this->append_format_output(fmt.c_str(), arg); @@ -579,7 +579,7 @@ void builtin_printf_state_t::print_direc(const wchar_t *start, size_t length, wc static inline void modify_allowed_format_specifiers(bool ok[UCHAR_MAX + 1], const char *str, bool flag) { for (const char *c = str; *c != '\0'; c++) { - unsigned char idx = static_cast(*c); + auto idx = static_cast(*c); ok[idx] = flag; } } @@ -654,7 +654,7 @@ int builtin_printf_state_t::print_formatted(const wchar_t *format, int argc, wch ++f; ++direc_length; if (argc > 0) { - intmax_t width = string_to_scalar_type(*argv, this); + auto width = string_to_scalar_type(*argv, this); if (INT_MIN <= width && width <= INT_MAX) field_width = static_cast(width); else @@ -679,7 +679,7 @@ int builtin_printf_state_t::print_formatted(const wchar_t *format, int argc, wch ++f; ++direc_length; if (argc > 0) { - intmax_t prec = string_to_scalar_type(*argv, this); + auto prec = string_to_scalar_type(*argv, this); if (prec < 0) { // A negative precision is taken as if the precision were omitted, // so -1 is safe here even if prec < INT_MIN. diff --git a/src/builtin_status.cpp b/src/builtin_status.cpp index 012a18f54..e35de167c 100644 --- a/src/builtin_status.cpp +++ b/src/builtin_status.cpp @@ -350,7 +350,7 @@ int builtin_status(parser_t &parser, io_streams_t &streams, wchar_t **argv) { streams.err.append_format(BUILTIN_ERR_ARG_COUNT2, cmd, subcmd_str, 1, args.size()); return STATUS_INVALID_ARGS; } - const auto *metadata = features_t::metadata_for(args.front().c_str()); + auto metadata = features_t::metadata_for(args.front().c_str()); if (!metadata) { retval = TEST_FEATURE_NOT_RECOGNIZED; } else { diff --git a/src/builtin_string.cpp b/src/builtin_string.cpp index 517be1f5a..525f63e73 100644 --- a/src/builtin_string.cpp +++ b/src/builtin_string.cpp @@ -871,7 +871,7 @@ class pcre2_matcher_t : public string_matcher_t { if (opts.invert_match) return true; // Report any additional matches. - for (auto *ovector = pcre2_get_ovector_pointer(regex.match); opts.all; total_matched++) { + for (auto ovector = pcre2_get_ovector_pointer(regex.match); opts.all; total_matched++) { uint32_t options = 0; PCRE2_SIZE offset = ovector[1]; // start at end of previous match @@ -1052,7 +1052,7 @@ bool regex_replacer_t::replace_matches(const wcstring &arg) { (opts.all ? PCRE2_SUBSTITUTE_GLOBAL : 0); size_t arglen = arg.length(); PCRE2_SIZE bufsize = (arglen == 0) ? 16 : 2 * arglen; - wchar_t *output = static_cast(malloc(sizeof(wchar_t) * bufsize)); + auto output = static_cast(malloc(sizeof(wchar_t) * bufsize)); int pcre2_rc; PCRE2_SIZE outlen = bufsize; @@ -1071,8 +1071,7 @@ bool regex_replacer_t::replace_matches(const wcstring &arg) { done = true; } else { bufsize = outlen; - wchar_t *new_output = - static_cast(realloc(output, sizeof(wchar_t) * bufsize)); + auto new_output = static_cast(realloc(output, sizeof(wchar_t) * bufsize)); if (new_output) output = new_output; } } @@ -1307,7 +1306,7 @@ static int string_sub(parser_t &parser, io_streams_t &streams, int argc, wchar_t pos = static_cast(opts.start - 1); } else if (opts.start < 0) { assert(opts.start != LONG_MIN); // checked above - size_type n = static_cast(-opts.start); + auto n = static_cast(-opts.start); pos = n > s->length() ? 0 : s->length() - n; } diff --git a/src/color.cpp b/src/color.cpp index bfb2a52c8..c80195c49 100644 --- a/src/color.cpp +++ b/src/color.cpp @@ -87,15 +87,15 @@ static int parse_hex_digit(wchar_t x) { } static unsigned long squared_difference(long p1, long p2) { - unsigned long diff = static_cast(labs(p1 - p2)); + auto diff = static_cast(labs(p1 - p2)); return diff * diff; } static unsigned char convert_color(const unsigned char rgb[3], const uint32_t *colors, size_t color_count) { long r = rgb[0], g = rgb[1], b = rgb[2]; - unsigned long best_distance = static_cast(-1); - unsigned char best_index = static_cast(-1); + auto best_distance = static_cast(-1); + auto best_index = static_cast(-1); for (size_t idx = 0; idx < color_count; idx++) { uint32_t color = colors[idx]; long test_r = (color >> 16) & 0xFF, test_g = (color >> 8) & 0xFF, diff --git a/src/common.cpp b/src/common.cpp index 0f33f7364..8271d4d94 100644 --- a/src/common.cpp +++ b/src/common.cpp @@ -361,7 +361,7 @@ char *wcs2str(const wchar_t *in, size_t len) { } // Here we probably allocate a buffer probably much larger than necessary. - char *out = static_cast(malloc(MAX_UTF8_BYTES * len + 1)); + auto out = static_cast(malloc(MAX_UTF8_BYTES * len + 1)); assert(out); // Instead of returning the return value of wcs2str_internal, return `out` directly. // This eliminates false warnings in coverity about resource leaks. @@ -1210,7 +1210,7 @@ wcstring debug_escape(const wcstring &in) { wcstring result; result.reserve(in.size()); for (wchar_t wc : in) { - uint32_t c = static_cast(wc); + auto c = static_cast(wc); if (c <= 127 && isprint(c)) { result.push_back(wc); continue; @@ -2148,7 +2148,7 @@ void assert_is_background_thread(const char *who) { } void assert_is_locked(void *vmutex, const char *who, const char *caller) { - std::mutex *mutex = static_cast(vmutex); + auto mutex = static_cast(vmutex); // Note that std::mutex.try_lock() is allowed to return false when the mutex isn't // actually locked; fortunately we are checking the opposite so we're safe. diff --git a/src/complete.cpp b/src/complete.cpp index 65e98b5de..bbc5a59e1 100644 --- a/src/complete.cpp +++ b/src/complete.cpp @@ -422,7 +422,7 @@ bool completer_t::condition_test(const wcstring &condition) { ASSERT_IS_MAIN_THREAD(); bool test_res; - condition_cache_t::iterator cached_entry = condition_cache.find(condition); + auto cached_entry = condition_cache.find(condition); if (cached_entry == condition_cache.end()) { // Compute new value and reinsert it. test_res = @@ -476,7 +476,7 @@ void complete_add(const wchar_t *cmd, bool cmd_is_path, const wcstring &option, /// option strings. Returns true if it is now empty and should be deleted, false if it's not empty. /// Must be called while locked. bool completion_entry_t::remove_option(const wcstring &option, complete_option_type_t type) { - option_list_t::iterator iter = this->options.begin(); + auto iter = this->options.begin(); while (iter != this->options.end()) { if (iter->option == option && iter->type == type) { iter = this->options.erase(iter); @@ -493,10 +493,10 @@ void complete_remove(const wcstring &cmd, bool cmd_is_path, const wcstring &opti auto completion_set = s_completion_set.acquire(); completion_entry_t tmp_entry(cmd, cmd_is_path); - completion_entry_set_t::iterator iter = completion_set->find(tmp_entry); + auto iter = completion_set->find(tmp_entry); if (iter != completion_set->end()) { // const_cast: See SET_ELEMENTS_ARE_IMMUTABLE. - completion_entry_t &entry = const_cast(*iter); + auto &entry = const_cast(*iter); bool delete_it = entry.remove_option(option, type); if (delete_it) { @@ -1788,7 +1788,7 @@ bool complete_remove_wrapper(const wcstring &command, const wcstring &target_to_ auto locked_map = wrapper_map.acquire(); wrapper_map_t &wraps = *locked_map; bool result = false; - wrapper_map_t::iterator current_targets_iter = wraps.find(command); + auto current_targets_iter = wraps.find(command); if (current_targets_iter != wraps.end()) { wcstring_list_t *targets = ¤t_targets_iter->second; auto where = std::find(targets->begin(), targets->end(), target_to_remove); diff --git a/src/env.cpp b/src/env.cpp index cdefd3161..d7c526403 100644 --- a/src/env.cpp +++ b/src/env.cpp @@ -107,7 +107,7 @@ const electric_var_t *electric_var_t::for_name(const wcstring &name) { /// Check if a variable may not be set using the set command. static bool is_read_only(const wcstring &key) { - if (const auto *ev = electric_var_t::for_name(key)) { + if (auto ev = electric_var_t::for_name(key)) { return ev->readonly(); } // Hack. diff --git a/src/env_universal_common.cpp b/src/env_universal_common.cpp index 507f2301f..3fab6cabc 100644 --- a/src/env_universal_common.cpp +++ b/src/env_universal_common.cpp @@ -253,13 +253,13 @@ env_universal_t::env_universal_t(wcstring path) : narrow_vars_path(wcs2string(path)), explicit_vars_path(std::move(path)) {} maybe_t env_universal_t::get(const wcstring &name) const { - var_table_t::const_iterator where = vars.find(name); + auto where = vars.find(name); if (where != vars.end()) return where->second; return none(); } maybe_t env_universal_t::get_flags(const wcstring &name) const { - var_table_t::const_iterator where = vars.find(name); + auto where = vars.find(name); if (where != vars.end()) { return where->second.get_flags(); } @@ -360,7 +360,7 @@ void env_universal_t::generate_callbacks_and_update_exports(const var_table_t &n void env_universal_t::acquire_variables(var_table_t &vars_to_acquire) { // Copy modified values from existing vars to vars_to_acquire. for (const auto &key : this->modified) { - var_table_t::iterator src_iter = this->vars.find(key); + auto src_iter = this->vars.find(key); if (src_iter == this->vars.end()) { /* The value has been deleted. */ vars_to_acquire.erase(key); diff --git a/src/exec.cpp b/src/exec.cpp index b575e7aa5..c8d58a5d7 100644 --- a/src/exec.cpp +++ b/src/exec.cpp @@ -93,8 +93,8 @@ static void safe_launch_process(process_t *p, const char *actual_cmd, const char int err; // This function never returns, so we take certain liberties with constness. - char *const *envv = const_cast(cenvv); - char *const *argv = const_cast(cargv); + const auto envv = const_cast(cenvv); + const auto argv = const_cast(cargv); execve(actual_cmd, argv, envv); err = errno; @@ -1062,8 +1062,7 @@ static void populate_subshell_output(wcstring_list_t *lst, const io_buffer_t &bu const char *cursor = begin; while (cursor < end) { // Look for the next separator. - const char *stop = - static_cast(std::memchr(cursor, '\n', end - cursor)); + auto stop = static_cast(std::memchr(cursor, '\n', end - cursor)); const bool hit_separator = (stop != nullptr); if (!hit_separator) { // If it's not found, just use the end. diff --git a/src/fallback.cpp b/src/fallback.cpp index 6b7ff3d62..30742136c 100644 --- a/src/fallback.cpp +++ b/src/fallback.cpp @@ -77,7 +77,7 @@ int fish_mkstemp_cloexec(char *name_template) { // cppcheck-suppress unusedFunction [[gnu::unused]] static wchar_t *wcsdup_fallback(const wchar_t *in) { size_t len = std::wcslen(in); - wchar_t *out = static_cast(malloc(sizeof(wchar_t) * (len + 1))); + auto out = static_cast(malloc(sizeof(wchar_t) * (len + 1))); if (out == nullptr) { return nullptr; } @@ -162,7 +162,7 @@ int wcsncasecmp(const wchar_t *a, const wchar_t *b, size_t n) { #ifndef HAVE_WCSNDUP wchar_t *wcsndup(const wchar_t *in, size_t c) { - wchar_t *res = static_cast(malloc(sizeof(wchar_t) * (c + 1))); + auto res = static_cast(malloc(sizeof(wchar_t) * (c + 1))); if (res == nullptr) { return nullptr; } diff --git a/src/fish.cpp b/src/fish.cpp index cbebe02cf..c75c52a1c 100644 --- a/src/fish.cpp +++ b/src/fish.cpp @@ -336,12 +336,12 @@ static int fish_parse_opt(int argc, char **argv, fish_cmd_opts_t *opts) { auto cats = get_flog_categories(); // Compute width of longest name. int name_width = 0; - for (const auto *cat : cats) { + for (auto cat : cats) { name_width = std::max(name_width, static_cast(wcslen(cat->name))); } // A little extra space. name_width += 2; - for (const auto *cat : cats) { + for (auto cat : cats) { // Negating the name width left-justifies. printf("%*ls %ls\n", -name_width, cat->name, _(cat->description)); } diff --git a/src/fish_tests.cpp b/src/fish_tests.cpp index a197dfa48..8312d12d5 100644 --- a/src/fish_tests.cpp +++ b/src/fish_tests.cpp @@ -810,8 +810,8 @@ static void test_fd_monitor() { item_oneshot.always_exit = true; { fd_monitor_t monitor; - for (auto *item : {&item_never, &item_hugetimeout, &item0_timeout, &item42_timeout, - &item42_nottimeout, &item42_thenclose, &item_oneshot}) { + for (auto item : {&item_never, &item_hugetimeout, &item0_timeout, &item42_timeout, + &item42_nottimeout, &item42_thenclose, &item_oneshot}) { monitor.add(std::move(item->item)); } item42_timeout.write42(); diff --git a/src/function.cpp b/src/function.cpp index 56e5fb2c5..e841d55fc 100644 --- a/src/function.cpp +++ b/src/function.cpp @@ -80,7 +80,7 @@ static owning_lock function_set; bool function_set_t::allow_autoload(const wcstring &name) const { // Prohibit autoloading if we have a non-autoload (explicit) function, or if the function is // tombstoned. - const auto *info = get_info(name); + auto info = get_info(name); bool has_explicit_func = info && !info->is_autoload; bool is_tombstoned = autoload_tombstones.count(name) > 0; return !has_explicit_func && !is_tombstoned; @@ -175,7 +175,7 @@ void function_add(wcstring name, wcstring description, function_properties_ref_t std::shared_ptr function_get_properties(const wcstring &name) { if (parser_keywords_is_reserved(name)) return nullptr; auto funcset = function_set.acquire(); - if (const auto *info = funcset->get_info(name)) { + if (auto info = funcset->get_info(name)) { return info->props; } return nullptr; diff --git a/src/history.cpp b/src/history.cpp index d783035d0..980fc50a5 100644 --- a/src/history.cpp +++ b/src/history.cpp @@ -466,8 +466,7 @@ void history_impl_t::set_valid_file_paths(const wcstring_list_t &valid_file_path } // Look for an item with the given identifier. It is likely to be at the end of new_items. - for (history_item_list_t::reverse_iterator iter = new_items.rbegin(); iter != new_items.rend(); - ++iter) { + for (auto iter = new_items.rbegin(); iter != new_items.rend(); ++iter) { if (iter->identifier == ident) { // found it iter->required_paths = valid_file_paths; break; @@ -603,7 +602,7 @@ void history_impl_t::load_old_if_needed() { bool history_search_t::go_backwards() { // Backwards means increasing our index. - const size_t max_index = static_cast(-1); + const auto max_index = static_cast(-1); if (current_index_ == max_index) return false; diff --git a/src/history_file.cpp b/src/history_file.cpp index 453c96dac..66cc2f548 100644 --- a/src/history_file.cpp +++ b/src/history_file.cpp @@ -29,7 +29,7 @@ static bool should_mmap(int fd) { // Return true on success, false on failure. static bool read_from_fd(int fd, void *address, size_t len) { size_t remaining = len; - char *ptr = static_cast(address); + auto ptr = static_cast(address); while (remaining > 0) { ssize_t amt = read(fd, ptr, remaining); if (amt < 0) { @@ -162,7 +162,7 @@ history_item_t history_file_contents_t::decode_item(size_t offset) const { } maybe_t history_file_contents_t::offset_of_next_item(size_t *cursor, time_t cutoff) { - size_t offset = size_t(-1); + auto offset = size_t(-1); switch (this->type()) { case history_type_fish_2_0: offset = offset_of_next_item_fish_2_0(*this, cursor, cutoff); @@ -183,7 +183,7 @@ static size_t read_line(const char *base, size_t cursor, size_t len, std::string // Locate the newline. assert(cursor <= len); const char *start = base + cursor; - const char *a_newline = static_cast(std::memchr(start, '\n', len - cursor)); + auto a_newline = static_cast(std::memchr(start, '\n', len - cursor)); if (a_newline != nullptr) { // we found a newline result.assign(start, a_newline - start); // Return the amount to advance the cursor; skip over the newline. @@ -342,7 +342,7 @@ static const char *next_line(const char *start, const char *end) { static size_t offset_of_next_item_fish_2_0(const history_file_contents_t &contents, size_t *inout_cursor, time_t cutoff_timestamp) { size_t cursor = *inout_cursor; - size_t result = size_t(-1); + auto result = size_t(-1); const size_t length = contents.length(); const char *const begin = contents.begin(); const char *const end = contents.end(); @@ -350,8 +350,7 @@ static size_t offset_of_next_item_fish_2_0(const history_file_contents_t &conten const char *line_start = contents.address_at(cursor); // Advance the cursor to the next line. - const char *a_newline = - static_cast(std::memchr(line_start, '\n', length - cursor)); + auto a_newline = static_cast(std::memchr(line_start, '\n', length - cursor)); if (a_newline == nullptr) break; // Advance the cursor past this line. +1 is for the newline. @@ -509,7 +508,7 @@ static history_item_t decode_item_fish_1_x(const char *begin, size_t length) { while (*time_string && !iswdigit(*time_string)) time_string++; if (*time_string) { - time_t tm = static_cast(fish_wcstol(time_string)); + auto tm = static_cast(fish_wcstol(time_string)); if (!errno && tm >= 0) { timestamp = tm; } diff --git a/src/io.cpp b/src/io.cpp index 42fabfd46..070dd2687 100644 --- a/src/io.cpp +++ b/src/io.cpp @@ -31,7 +31,7 @@ /// Provide the fd monitor used for background fillthread operations. static fd_monitor_t &fd_monitor() { // Deliberately leaked to avoid shutdown dtors. - static fd_monitor_t *fdm = new fd_monitor_t(); + static auto fdm = new fd_monitor_t(); return *fdm; } @@ -202,7 +202,7 @@ io_buffer_t::~io_buffer_t() { void io_chain_t::remove(const shared_ptr &element) { // See if you can guess why std::find doesn't work here. - for (io_chain_t::iterator iter = this->begin(); iter != this->end(); ++iter) { + for (auto iter = this->begin(); iter != this->end(); ++iter) { if (*iter == element) { this->erase(iter); break; diff --git a/src/iothread.cpp b/src/iothread.cpp index b4a8ea651..c7a32f376 100644 --- a/src/iothread.cpp +++ b/src/iothread.cpp @@ -466,7 +466,7 @@ using void_func_t = std::function; static void *func_invoker(void *param) { // Acquire a thread id for this thread. (void)thread_id(); - void_func_t *vf = static_cast(param); + auto vf = static_cast(param); (*vf)(); delete vf; return nullptr; @@ -474,7 +474,7 @@ static void *func_invoker(void *param) { bool make_detached_pthread(void_func_t &&func) { // Copy the function into a heap allocation. - void_func_t *vf = new void_func_t(std::move(func)); + auto vf = new void_func_t(std::move(func)); if (make_detached_pthread(func_invoker, vf)) { return true; } diff --git a/src/null_terminated_array.cpp b/src/null_terminated_array.cpp index 368584d7f..033f60881 100644 --- a/src/null_terminated_array.cpp +++ b/src/null_terminated_array.cpp @@ -22,13 +22,13 @@ static CharT **make_null_terminated_array_helper( } // Now allocate their sum. - unsigned char *base = + auto base = static_cast(malloc(pointers_allocation_len + strings_allocation_len)); if (!base) return nullptr; // Divvy it up into the pointers and strings. - CharT **pointers = reinterpret_cast(base); - CharT *strings = reinterpret_cast(base + pointers_allocation_len); + auto pointers = reinterpret_cast(base); + auto strings = reinterpret_cast(base + pointers_allocation_len); // Start copying. for (size_t i = 0; i < count; i++) { diff --git a/src/null_terminated_array.h b/src/null_terminated_array.h index 59950be75..ec8bccdc9 100644 --- a/src/null_terminated_array.h +++ b/src/null_terminated_array.h @@ -64,7 +64,7 @@ class null_terminated_array_t { /// Convert from a null terminated list to a vector of strings. static string_list_t to_list(const CharT *const *arr) { string_list_t result; - for (const auto *cursor = arr; cursor && *cursor; cursor++) { + for (auto cursor = arr; cursor && *cursor; cursor++) { result.push_back(*cursor); } return result; diff --git a/src/pager.cpp b/src/pager.cpp index c8a0622b6..672005b70 100644 --- a/src/pager.cpp +++ b/src/pager.cpp @@ -84,7 +84,7 @@ static size_t print_max(const wcstring &str, highlight_spec_t color, size_t max, // skip non-printable characters continue; } - size_t width_c = size_t(iwidth_c); + auto width_c = size_t(iwidth_c); if (width_c > remaining) break; @@ -139,7 +139,7 @@ line_t pager_t::completion_print_item(const wcstring &prefix, const comp_t *c, s auto modify_role = [=](highlight_role_t role) -> highlight_role_t { using uint_t = typename std::underlying_type::type; - uint_t base = static_cast(role); + auto base = static_cast(role); if (selected) { base += static_cast(highlight_role_t::pager_selected_background) - static_cast(highlight_role_t::pager_background); diff --git a/src/parse_tree.cpp b/src/parse_tree.cpp index 9b9c745b6..46ee115ab 100644 --- a/src/parse_tree.cpp +++ b/src/parse_tree.cpp @@ -453,7 +453,7 @@ class parse_ll_t { // it's lowest on the stack) const size_t child_start_big = nodes.size(); assert(child_start_big < NODE_OFFSET_INVALID); - node_offset_t child_start = static_cast(child_start_big); + auto child_start = static_cast(child_start_big); // To avoid constructing multiple nodes, we make a single one that we modify. parse_node_t representative_child(token_type_invalid); @@ -728,7 +728,7 @@ void parse_ll_t::parse_error_unexpected_token(const wchar_t *expected, parse_tok void parse_ll_t::reset_symbols(enum parse_token_type_t goal) { // Add a new goal node, and then reset our symbol list to point at it. - node_offset_t where = static_cast(nodes.size()); + auto where = static_cast(nodes.size()); nodes.push_back(parse_node_t(goal)); symbol_stack.clear(); diff --git a/src/proc.cpp b/src/proc.cpp index 1bd91739c..a050e9e66 100644 --- a/src/proc.cpp +++ b/src/proc.cpp @@ -96,7 +96,7 @@ void proc_init() { signal_set_handlers_once(false); } // Basic thread safe sorted vector of job IDs in use. // This is deliberately leaked to avoid dtor ordering issues - see #6539. -static auto *const locked_consumed_job_ids = new owning_lock>(); +static const auto locked_consumed_job_ids = new owning_lock>(); job_id_t acquire_job_id() { auto consumed_job_ids = locked_consumed_job_ids->acquire(); diff --git a/src/reader.cpp b/src/reader.cpp index a35bd2f51..67014577d 100644 --- a/src/reader.cpp +++ b/src/reader.cpp @@ -148,13 +148,13 @@ operation_context_t get_bg_context(const std::shared_ptr &env, /// These are deliberately leaked to avoid shutdown dtor registration. static debounce_t &debounce_autosuggestions() { const long kAutosuggetTimeoutMs = 500; - static debounce_t *res = new debounce_t(kAutosuggetTimeoutMs); + static auto res = new debounce_t(kAutosuggetTimeoutMs); return *res; } static debounce_t &debounce_highlighting() { const long kHighlightTimeoutMs = 500; - static debounce_t *res = new debounce_t(kHighlightTimeoutMs); + static auto res = new debounce_t(kHighlightTimeoutMs); return *res; } @@ -549,7 +549,7 @@ class reader_data_t : public std::enable_shared_from_this { } editable_line_t *active_edit_line() { - const auto *cthis = this; + auto cthis = reinterpret_cast(this); return const_cast(cthis->active_edit_line()); } diff --git a/src/tinyexpr.cpp b/src/tinyexpr.cpp index e134b6cb7..dc1206154 100644 --- a/src/tinyexpr.cpp +++ b/src/tinyexpr.cpp @@ -109,7 +109,7 @@ static te_expr *new_expr(const int type, const te_expr *parameters[]) { const int arity = get_arity(type); const int psize = sizeof(te_expr *) * arity; const int size = sizeof(te_expr) + psize; - te_expr *ret = static_cast(malloc(size)); + auto ret = static_cast(malloc(size)); // This sets float to 0, which depends on the implementation. // We rely on IEEE-754 floats anyway, so it's okay. std::memset(ret, 0, size); @@ -142,7 +142,7 @@ static constexpr double e() { return M_E; } static double fac(double a) { /* simplest version of fac */ if (a < 0.0) return NAN; if (a > UINT_MAX) return INFINITY; - unsigned int ua = static_cast(a); + auto ua = static_cast(a); unsigned long int result = 1, i; for (i = 1; i <= ua; i++) { if (i > ULONG_MAX / result) return INFINITY; @@ -448,7 +448,7 @@ static te_expr *factor(state *s) { while (s->type == TOK_INFIX && (s->function == reinterpret_cast(static_cast(pow)))) { - te_fun2 t = (te_fun2)s->function; + auto t = (te_fun2)s->function; next_token(s); if (insertion) { @@ -475,7 +475,7 @@ static te_expr *term(state *s) { (s->function == reinterpret_cast(static_cast(mul)) || s->function == reinterpret_cast(static_cast(divide)) || s->function == reinterpret_cast(static_cast(fmod)))) { - te_fun2 t = (te_fun2)s->function; + auto t = (te_fun2)s->function; next_token(s); ret = NEW_EXPR(TE_FUNCTION2, ret, factor(s)); ret->function = reinterpret_cast(t); @@ -489,7 +489,7 @@ static te_expr *expr(state *s) { te_expr *ret = term(s); while (s->type == TOK_INFIX && (s->function == add || s->function == sub)) { - te_fun2 t = (te_fun2)s->function; + auto t = (te_fun2)s->function; next_token(s); ret = NEW_EXPR(TE_FUNCTION2, ret, term(s)); ret->function = reinterpret_cast(t); diff --git a/src/utf8.cpp b/src/utf8.cpp index 1086fd8f1..f52d3100a 100644 --- a/src/utf8.cpp +++ b/src/utf8.cpp @@ -67,7 +67,7 @@ bool wchar_to_utf8_string(const std::wstring &str, std::string *result) { const wchar_t *input = str.c_str(); size_t outlen = wchar_to_utf8(input, inlen, nullptr, 0, 0); if (outlen > 0) { - char *tmp = new char[outlen]; + auto tmp = new char[outlen]; size_t outlen2 = wchar_to_utf8(input, inlen, tmp, outlen, 0); if (outlen2 > 0) { result->assign(tmp, outlen2); @@ -110,7 +110,7 @@ size_t wchar_to_utf8(const wchar_t *in, size_t insize, char *out, size_t outsize } else { // Allocate a temporary buffer to hold the input the std::copy performs the size conversion. // Note: insize may be 0. - utf8_wchar_t *tmp_input = new utf8_wchar_t[insize]; + auto tmp_input = new utf8_wchar_t[insize]; if (!safe_copy_wchar_to_utf8_wchar(in, tmp_input, insize)) { // Our utf8_wchar_t is UCS-16 and there was an astral character. result = 0;