diff --git a/src/builtin_argparse.cpp b/src/builtin_argparse.cpp index 9a5334cd0..a7f2b1f53 100644 --- a/src/builtin_argparse.cpp +++ b/src/builtin_argparse.cpp @@ -330,7 +330,7 @@ static int collect_option_specs(argparse_cmd_opts_t &opts, int *optind, int argc // A counter to give short chars to long-only options because getopt needs that. // Luckily we have wgetopt so we can use wchars - this is one of the private use areas so we // have 6400 options available. - wchar_t counter = static_cast(0xE000); + auto counter = static_cast(0xE000); while (true) { if (std::wcscmp(L"--", argv[*optind]) == 0) { diff --git a/src/builtin_set.cpp b/src/builtin_set.cpp index ffca47886..c56aa364c 100644 --- a/src/builtin_set.cpp +++ b/src/builtin_set.cpp @@ -683,7 +683,7 @@ static wcstring_list_t new_var_values_by_index(const split_var_t &split, int arg long lidx = split.indexes.at(i); assert(lidx >= 1 && "idx should have been verified in range already"); // Convert from 1-based to 0-based. - size_t idx = static_cast(lidx - 1); + auto idx = static_cast(lidx - 1); // Extend as needed with empty strings. if (idx >= result.size()) result.resize(idx + 1); result.at(idx) = argv[i]; diff --git a/src/builtin_string.cpp b/src/builtin_string.cpp index c40c60b94..f15ef5163 100644 --- a/src/builtin_string.cpp +++ b/src/builtin_string.cpp @@ -1673,7 +1673,7 @@ static wcstring wcsrepeat(const wcstring &to_repeat, size_t count) { // Helper function to abstract the repeat until logic from string_repeat // returns the to_repeat string, repeated until max char has been reached. static wcstring wcsrepeat_until(const wcstring &to_repeat, size_t max) { - if (to_repeat.length() == 0) return wcstring(); + if (to_repeat.length() == 0) return {}; size_t count = max / to_repeat.length(); size_t mod = max % to_repeat.length(); diff --git a/src/env.cpp b/src/env.cpp index 3282b8aa6..3658b13ea 100644 --- a/src/env.cpp +++ b/src/env.cpp @@ -61,8 +61,7 @@ bool term_has_xn = false; /// This is typically initialized in env_init(), and is considered empty before then. static acquired_lock uvars() { // Leaked to avoid shutdown dtor registration. - static owning_lock *const s_universal_variables = - new owning_lock(); + static auto const s_universal_variables = new owning_lock(); return s_universal_variables->acquire(); } @@ -843,7 +842,7 @@ wcstring_list_t env_scoped_impl_t::get_names(int flags) const { names.insert(uni_list.begin(), uni_list.end()); } - return wcstring_list_t(names.begin(), names.end()); + return {names.begin(), names.end()}; } /// Recursive helper to snapshot a series of nodes. diff --git a/src/fallback.cpp b/src/fallback.cpp index b60cfb4e2..c93d685be 100644 --- a/src/fallback.cpp +++ b/src/fallback.cpp @@ -263,7 +263,6 @@ int fish_wcwidth(wchar_t wc) { // Fall back to system wcwidth in this case. return wcwidth(wc); case widechar_ambiguous: - return g_fish_ambiguous_width; case widechar_private_use: // TR11: "All private-use characters are by default classified as Ambiguous". return g_fish_ambiguous_width; diff --git a/src/highlight.cpp b/src/highlight.cpp index 0ae4a37cd..c99024dd8 100644 --- a/src/highlight.cpp +++ b/src/highlight.cpp @@ -104,61 +104,41 @@ static const wchar_t *get_highlight_var_name(highlight_role_t role) { static highlight_role_t get_fallback(highlight_role_t role) { switch (role) { case highlight_role_t::normal: - return highlight_role_t::normal; case highlight_role_t::error: - return highlight_role_t::normal; case highlight_role_t::command: + case highlight_role_t::statement_terminator: + case highlight_role_t::param: + case highlight_role_t::search_match: + case highlight_role_t::comment: + case highlight_role_t::operat: + case highlight_role_t::escape: + case highlight_role_t::quote: + case highlight_role_t::redirection: + case highlight_role_t::autosuggestion: + case highlight_role_t::selection: + case highlight_role_t::pager_progress: + case highlight_role_t::pager_background: + case highlight_role_t::pager_prefix: + case highlight_role_t::pager_completion: + case highlight_role_t::pager_description: return highlight_role_t::normal; case highlight_role_t::keyword: return highlight_role_t::command; - case highlight_role_t::statement_terminator: - return highlight_role_t::normal; case highlight_role_t::option: return highlight_role_t::param; - case highlight_role_t::param: - return highlight_role_t::normal; - case highlight_role_t::comment: - return highlight_role_t::normal; - case highlight_role_t::search_match: - return highlight_role_t::normal; - case highlight_role_t::operat: - return highlight_role_t::normal; - case highlight_role_t::escape: - return highlight_role_t::normal; - case highlight_role_t::quote: - return highlight_role_t::normal; - case highlight_role_t::redirection: - return highlight_role_t::normal; - case highlight_role_t::autosuggestion: - return highlight_role_t::normal; - case highlight_role_t::selection: - return highlight_role_t::normal; - case highlight_role_t::pager_progress: - return highlight_role_t::normal; - case highlight_role_t::pager_background: - return highlight_role_t::normal; - case highlight_role_t::pager_prefix: - return highlight_role_t::normal; - case highlight_role_t::pager_completion: - return highlight_role_t::normal; - case highlight_role_t::pager_description: - return highlight_role_t::normal; case highlight_role_t::pager_secondary_background: return highlight_role_t::pager_background; case highlight_role_t::pager_secondary_prefix: + case highlight_role_t::pager_selected_prefix: return highlight_role_t::pager_prefix; case highlight_role_t::pager_secondary_completion: + case highlight_role_t::pager_selected_completion: return highlight_role_t::pager_completion; case highlight_role_t::pager_secondary_description: + case highlight_role_t::pager_selected_description: return highlight_role_t::pager_description; case highlight_role_t::pager_selected_background: return highlight_role_t::search_match; - case highlight_role_t::pager_selected_prefix: - return highlight_role_t::pager_prefix; - case highlight_role_t::pager_selected_completion: - return highlight_role_t::pager_completion; - case highlight_role_t::pager_selected_description: - return highlight_role_t::pager_description; } DIE("invalid highlight role"); } @@ -175,7 +155,7 @@ static bool fs_is_case_insensitive(const wcstring &path, int fd, bool result = false; #ifdef _PC_CASE_SENSITIVE // Try the cache first. - case_sensitivity_cache_t::iterator cache = case_sensitivity_cache.find(path); + auto cache = case_sensitivity_cache.find(path); if (cache != case_sensitivity_cache.end()) { /* Use the cached value */ result = cache->second; @@ -518,7 +498,7 @@ static size_t color_variable(const wchar_t *in, size_t in_len, for (size_t slice_count = 0; slice_count < dollar_count; slice_count++) { long slice_len = parse_util_slice_length(in + idx); if (slice_len > 0) { - size_t slice_ulen = static_cast(slice_len); + auto slice_ulen = static_cast(slice_len); colors[idx] = highlight_role_t::operat; colors[idx + slice_ulen - 1] = highlight_role_t::operat; idx += slice_ulen; @@ -1276,7 +1256,7 @@ highlighter_t::color_array_t highlighter_t::highlight() { // Underline every valid path. if (io_ok) { for (const ast::node_t &node : ast) { - const ast::argument_t *arg = node.try_as(); + const auto arg = node.try_as(); if (!arg || arg->unsourced) continue; if (ctx.check_cancel()) break; if (range_is_potential_path(buff, arg->range, ctx, working_directory)) { diff --git a/src/iothread.cpp b/src/iothread.cpp index d21cfe0e8..529a8878c 100644 --- a/src/iothread.cpp +++ b/src/iothread.cpp @@ -137,7 +137,7 @@ static owning_lock s_main_thread_queue; /// \return the signaller for completions and main thread requests. static fd_event_signaller_t &get_notify_signaller() { // Leaked to avoid shutdown dtors. - static fd_event_signaller_t *s_signaller = new fd_event_signaller_t(); + static auto s_signaller = new fd_event_signaller_t(); return *s_signaller; } @@ -356,7 +356,7 @@ bool make_detached_pthread(void *(*func)(void *), void *param) { // Spawn a thread. If this fails, it means there's already a bunch of threads; it is very // unlikely that they are all on the verge of exiting, so one is likely to be ready to handle // extant requests. So we can ignore failure with some confidence. - pthread_t thread = 0; + pthread_t thread = nullptr; int err = pthread_create(&thread, nullptr, func, param); if (err == 0) { // Success, return the thread. diff --git a/src/screen.cpp b/src/screen.cpp index 1a60da1f6..28b6d19ee 100644 --- a/src/screen.cpp +++ b/src/screen.cpp @@ -522,7 +522,7 @@ void screen_t::desired_append_char(wchar_t b, highlight_spec_t c, int indent, si this->desired.line(this->desired.cursor.y).is_soft_wrapped = false; int line_no = ++this->desired.cursor.y; this->desired.cursor.x = 0; - size_t indentation = prompt_width + indent * INDENT_STEP; + size_t indentation = prompt_width + static_cast(indent) * INDENT_STEP; line_t &line = this->desired.line(line_no); line.indentation = indentation; for (size_t i = 0; i < indentation; i++) { diff --git a/src/wutil.cpp b/src/wutil.cpp index 300da2ecb..476a4a4d7 100644 --- a/src/wutil.cpp +++ b/src/wutil.cpp @@ -464,7 +464,7 @@ ssize_t wwrite_to_fd(const wchar_t *input, size_t input_len, int fd) { ssize_t samt = write(fd, cursor, remaining); if (samt < 0) return false; total_written += samt; - size_t amt = static_cast(samt); + auto amt = static_cast(samt); assert(amt <= remaining && "Wrote more than requested"); remaining -= amt; cursor += amt; @@ -547,9 +547,9 @@ void fish_invalidate_numeric_locale() { locale_t fish_numeric_locale() { // The current locale, except LC_NUMERIC isn't forced to C. - static locale_t loc = 0; + static locale_t loc = nullptr; if (!fish_numeric_locale_is_valid) { - if (loc != 0) freelocale(loc); + if (loc != nullptr) freelocale(loc); auto cur = duplocale(LC_GLOBAL_LOCALE); loc = newlocale(LC_NUMERIC_MASK, "", cur); fish_numeric_locale_is_valid = true;