Ensure we continue to cover enums in switches

Where we already manage to cover an enum entirely in a switch
statement such that default: cannot be reached, help ensure
it stays that way by condemning that route.

Also adjust a 'const' I came across that is ignored.
This commit is contained in:
Aaron Gyes 2016-07-30 11:48:39 -07:00
parent acfd380176
commit ee26eafc25
9 changed files with 30 additions and 16 deletions

View file

@ -2831,7 +2831,8 @@ static const wcstring hist_cmd_to_string(hist_cmd_t hist_cmd) {
case HIST_SAVE:
return L"save";
default:
DIE("Unhandled history command");
assert(0 && "Unhandled hist_cmd_t constant!");
abort();
}
}

View file

@ -131,14 +131,19 @@ enum selection_direction_t {
inline bool selection_direction_is_cardinal(selection_direction_t dir) {
switch (dir) {
case direction_north:
case direction_page_north:
case direction_east:
case direction_page_south:
case direction_south:
case direction_west: {
case direction_west:
case direction_page_north:
case direction_page_south: {
return true;
}
default: { return false; }
case direction_next:
case direction_prev:
case direction_deselect: {
return false;
}
default: { abort(); }
}
}

View file

@ -280,7 +280,10 @@ static void universal_callback(fish_message_type_t type, const wchar_t *name, co
str = L"ERASE";
break;
}
default: { break; }
default: {
assert(0 && "Unhandled fish_message_type_t constant!");
abort();
}
}
if (str) {

View file

@ -283,9 +283,8 @@ static bool io_transmogrify(const io_chain_t &in_chain, io_chain_t *out_chain,
}
default: {
// Unknown type, should never happen.
fprintf(stderr, "Unknown io_mode %ld\n", (long)in->io_mode);
assert(0 && "Unhandled io_mode constant");
abort();
break;
}
}

View file

@ -449,7 +449,7 @@ bool history_item_t::matches_search(const wcstring &term, enum history_search_ty
}
default: {
sanity_lose();
return false;
abort();
}
}
}

View file

@ -3,6 +3,7 @@
// IWYU pragma: no_include <cstddef>
#include <assert.h>
#include <stddef.h>
#include <stdlib.h>
#include <wchar.h>
#include <wctype.h>
#include <map>
@ -602,11 +603,14 @@ bool pager_t::select_next_completion_in_direction(selection_direction_t directio
case direction_page_north:
case direction_east:
case direction_west:
case direction_deselect:
default: {
case direction_deselect: {
// These do nothing.
return false;
}
default: {
assert(0 && "Unhandled selection_direction_t constant");
abort();
}
}
}

View file

@ -3,6 +3,7 @@
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include <wchar.h>
#include <algorithm>
#include <memory>
@ -255,7 +256,7 @@ block_t *parser_t::block_at_index(size_t idx) {
return idx < count ? block_stack.at(count - idx - 1) : NULL;
}
block_t *const parser_t::current_block() { return block_stack.empty() ? NULL : block_stack.back(); }
block_t *parser_t::current_block() { return block_stack.empty() ? NULL : block_stack.back(); }
void parser_t::forbid_function(const wcstring &function) { forbidden_function.push_back(function); }
@ -869,8 +870,8 @@ wcstring block_t::description() const {
break;
}
default: {
append_format(result, L"unknown type %ld", (long)this->type());
break;
assert(0 && "Unhandled block_type_t constant");
abort();
}
}

View file

@ -271,7 +271,7 @@ class parser_t {
block_t *block_at_index(size_t idx);
/// Returns the current (innermost) block.
block_t *const current_block();
block_t *current_block();
/// Count of blocks.
size_t block_count() const { return block_stack.size(); }

View file

@ -5,6 +5,7 @@
#include <assert.h>
#include <fcntl.h>
#include <limits.h>
#include <stdlib.h>
#include <unistd.h>
#include <wchar.h>
#include <wctype.h>
@ -759,7 +760,7 @@ bool move_word_state_machine_t::consume_char(wchar_t c) {
case move_word_style_whitespace: {
return consume_char_whitespace(c);
}
default: { return false; }
default: { abort(); }
}
}