From 2ae6e5a5858571d52ec6fedc568627661c596f53 Mon Sep 17 00:00:00 2001 From: Aaron Gyes Date: Mon, 11 Mar 2019 14:53:26 -0700 Subject: [PATCH] Explicitly handle all enum values in more switch statements This addresses a few places where -Wswitch-enum showed one or two missing case's for enum values. It did uncover and fix one apparent oversight: $ function asd -p 100 echo foo end $ functions --handlers-type exit Event exit asd It looks like this should be showing a PID before 'asd' just like job_exit handlers show the job id. It was falling through to default: which just printed the function name. $ functions --handlers-type exit Event exit 100 asd --- src/builtin_functions.cpp | 1 + src/builtin_math.cpp | 2 +- src/common.h | 17 +++++++++++++++-- src/event.cpp | 8 ++++++-- src/tokenizer.cpp | 5 ++++- 5 files changed, 27 insertions(+), 6 deletions(-) diff --git a/src/builtin_functions.cpp b/src/builtin_functions.cpp index 860f675e7..071d1cad2 100644 --- a/src/builtin_functions.cpp +++ b/src/builtin_functions.cpp @@ -176,6 +176,7 @@ static wcstring functions_def(const wcstring &name) { append_format(out, L" --on-event %ls", d.str_param1.c_str()); break; } + case event_type_t::any: default: { DIE("unexpected next->type"); break; diff --git a/src/builtin_math.cpp b/src/builtin_math.cpp index 506f80a5c..a98ea5b74 100644 --- a/src/builtin_math.cpp +++ b/src/builtin_math.cpp @@ -131,9 +131,9 @@ static const wchar_t *math_get_arg(int *argidx, wchar_t **argv, wcstring *storag static wcstring math_describe_error(te_error_t& error) { if (error.position == 0) return L"NO ERROR?!?"; - assert(error.type != TE_ERROR_NONE && L"Error has no position"); switch(error.type) { + case TE_ERROR_NONE: DIE("Error has no position"); case TE_ERROR_UNKNOWN_VARIABLE: return _(L"Unknown variable"); case TE_ERROR_MISSING_CLOSING_PAREN: return _(L"Missing closing parenthesis"); case TE_ERROR_MISSING_OPENING_PAREN: return _(L"Missing opening parenthesis"); diff --git a/src/common.h b/src/common.h index d99524cd4..6007b4317 100644 --- a/src/common.h +++ b/src/common.h @@ -429,7 +429,15 @@ static inline bool match_type_requires_full_replacement(fuzzy_match_type_t t) { case fuzzy_match_prefix: { return false; } - default: { return true; } + case fuzzy_match_case_insensitive: + case fuzzy_match_prefix_case_insensitive: + case fuzzy_match_substring: + case fuzzy_match_substring_case_insensitive: + case fuzzy_match_subsequence_insertions_only: + case fuzzy_match_none: + { + return true; + } } } @@ -442,7 +450,12 @@ static inline bool match_type_shares_prefix(fuzzy_match_type_t t) { case fuzzy_match_prefix_case_insensitive: { return true; } - default: { return false; } + case fuzzy_match_substring: + case fuzzy_match_substring_case_insensitive: + case fuzzy_match_subsequence_insertions_only: + case fuzzy_match_none: { + return false; + } } } diff --git a/src/event.cpp b/src/event.cpp index f04afefc0..79bbdd693 100644 --- a/src/event.cpp +++ b/src/event.cpp @@ -120,7 +120,8 @@ static bool handler_matches(const event_handler_t &classv, const event_t &instan case event_type_t::generic: { return classv.desc.str_param1 == instance.desc.str_param1; } - default: { + case event_type_t::any: { + default: DIE("unexpected classv.type"); return false; } @@ -165,7 +166,7 @@ wcstring event_get_desc(const event_t &evt) { -ed.param1.pid); } } - assert(0 && "Unreachable"); + DIE("Unreachable"); } case event_type_t::job_exit: { @@ -182,6 +183,7 @@ wcstring event_get_desc(const event_t &evt) { case event_type_t::generic: { return format_string(_(L"handler for generic event '%ls'"), ed.str_param1.c_str()); } + case event_type_t::any: { DIE("Unreachable"); } default: DIE("Unknown event type"); } @@ -409,6 +411,7 @@ void event_print(io_streams_t &streams, maybe_t type_filter) { streams.out.append_format(L"%ls %ls\n", sig2wcs(evt->desc.param1.signal), evt->function_name.c_str()); break; + case event_type_t::exit: case event_type_t::job_exit: streams.out.append_format(L"%d %ls\n", evt->desc.param1, evt->function_name.c_str()); @@ -418,6 +421,7 @@ void event_print(io_streams_t &streams, maybe_t type_filter) { streams.out.append_format(L"%ls %ls\n", evt->desc.str_param1.c_str(), evt->function_name.c_str()); break; + case event_type_t::any: DIE("Unreachable"); default: streams.out.append_format(L"%ls\n", evt->function_name.c_str()); break; diff --git a/src/tokenizer.cpp b/src/tokenizer.cpp index fd997a361..38ec77029 100644 --- a/src/tokenizer.cpp +++ b/src/tokenizer.cpp @@ -408,7 +408,10 @@ int oflags_for_redirection_type(redirection_type_t type) { case redirection_type_t::input: { return O_RDONLY; } - default: { return -1; } + case redirection_type_t::fd: + default: { + return -1; + } } }